diff --git a/docs/classes/Akamai_Open_EdgeGrid_Cli.html b/docs/classes/Akamai_Open_EdgeGrid_Cli.html index 487da60..9ef9735 100644 --- a/docs/classes/Akamai_Open_EdgeGrid_Cli.html +++ b/docs/classes/Akamai_Open_EdgeGrid_Cli.html @@ -69,12 +69,15 @@

Akamai\Open\EdgeGrid\Cli

Synopsis

class Cli - {
@@ -83,12 +86,12 @@

Coverage

Methods 0% - 0 / 5 + 0 / 8 Lines 0% - 0 / 107 + 0 / 181

Members

@@ -97,7 +100,7 @@

protected

Methods

@@ -107,6 +110,12 @@

protected

  • executeCommand()
  • +
  • + getArgValue() +
  • +
  • + getNamedArgs() +
  • parseArguments()
  • @@ -122,6 +131,9 @@

    public

  • run()
  • +
  • + version() +
  • diff --git a/docs/classes/Akamai_Open_EdgeGrid_Cli/__construct.html b/docs/classes/Akamai_Open_EdgeGrid_Cli/__construct.html index 705e02a..13453ed 100644 --- a/docs/classes/Akamai_Open_EdgeGrid_Cli/__construct.html +++ b/docs/classes/Akamai_Open_EdgeGrid_Cli/__construct.html @@ -73,7 +73,7 @@

    Test Coverage

    Information

    diff --git a/docs/classes/Akamai_Open_EdgeGrid_Cli/executeCommand.html b/docs/classes/Akamai_Open_EdgeGrid_Cli/executeCommand.html index efc1760..3662c88 100644 --- a/docs/classes/Akamai_Open_EdgeGrid_Cli/executeCommand.html +++ b/docs/classes/Akamai_Open_EdgeGrid_Cli/executeCommand.html @@ -56,7 +56,7 @@ Tests
  • - Source + Source
  • @@ -73,7 +73,7 @@

    Test Coverage

    Information

    diff --git a/docs/classes/Akamai_Open_EdgeGrid_Cli/getArgValue.html b/docs/classes/Akamai_Open_EdgeGrid_Cli/getArgValue.html new file mode 100644 index 0000000..435c85f --- /dev/null +++ b/docs/classes/Akamai_Open_EdgeGrid_Cli/getArgValue.html @@ -0,0 +1,98 @@ + + + + + phpDox - Test Method + + + + + +
    +
    + +
    + +
    +

    Akamai\Open\EdgeGrid\Cli::getArgValue

    +

    +

    +

    Signature

    +
    + protected function getArgValue( + $matches ) + +
    +

    Parameters

    +
    +
    $matches + — +
    +
    +
    +

    Test Coverage

    +
    +

    Information

    +
      +
    • Coverage: 0/8 Lines (0%)
    • +
    • Tests: 0
    • +
    • Passed: 0 (0%)
    • +
    +
    +
    +
    +
    + Generated using phpDox 0.8.2-dev - Copyright (C) 2010 - 2015 by Arne Blankerts +
    + + diff --git a/docs/classes/Akamai_Open_EdgeGrid_Cli/getNamedArgs.html b/docs/classes/Akamai_Open_EdgeGrid_Cli/getNamedArgs.html new file mode 100644 index 0000000..50c5c06 --- /dev/null +++ b/docs/classes/Akamai_Open_EdgeGrid_Cli/getNamedArgs.html @@ -0,0 +1,96 @@ + + + + + phpDox - Test Method + + + + + +
    +
    + +
    + +
    +

    Akamai\Open\EdgeGrid\Cli::getNamedArgs

    +

    +

    +

      +

      Signature

      +
      + protected function getNamedArgs() + +
      +

      Returns

      +
      +
      array
      +
      +
      +

      Test Coverage

      +
      +

      Information

      +
        +
      • Coverage: 0/27 Lines (0%)
      • +
      • Tests: 0
      • +
      • Passed: 0 (0%)
      • +
      +
      +

    +
    +
    + Generated using phpDox 0.8.2-dev - Copyright (C) 2010 - 2015 by Arne Blankerts +
    + + diff --git a/docs/classes/Akamai_Open_EdgeGrid_Cli/help.html b/docs/classes/Akamai_Open_EdgeGrid_Cli/help.html index 51ffcea..0075a1a 100644 --- a/docs/classes/Akamai_Open_EdgeGrid_Cli/help.html +++ b/docs/classes/Akamai_Open_EdgeGrid_Cli/help.html @@ -56,7 +56,7 @@ Tests
  • - Source + Source
  • @@ -73,7 +73,7 @@

    Test Coverage

    Information

      -
    • Coverage: 0/2 Lines (0%)
    • +
    • Coverage: 0/5 Lines (0%)
    • Tests: 0
    • Passed: 0 (0%)
    diff --git a/docs/classes/Akamai_Open_EdgeGrid_Cli/parseArguments.html b/docs/classes/Akamai_Open_EdgeGrid_Cli/parseArguments.html index a15647b..302ef79 100644 --- a/docs/classes/Akamai_Open_EdgeGrid_Cli/parseArguments.html +++ b/docs/classes/Akamai_Open_EdgeGrid_Cli/parseArguments.html @@ -73,7 +73,7 @@

    Test Coverage

    Information

      -
    • Coverage: 0/30 Lines (0%)
    • +
    • Coverage: 0/26 Lines (0%)
    • Tests: 0
    • Passed: 0 (0%)
    diff --git a/docs/classes/Akamai_Open_EdgeGrid_Cli/run.html b/docs/classes/Akamai_Open_EdgeGrid_Cli/run.html index 45c7f17..79c1fad 100644 --- a/docs/classes/Akamai_Open_EdgeGrid_Cli/run.html +++ b/docs/classes/Akamai_Open_EdgeGrid_Cli/run.html @@ -56,7 +56,7 @@ Tests
  • - Source + Source
  • @@ -73,7 +73,7 @@

    Test Coverage

    Information

      -
    • Coverage: 0/3 Lines (0%)
    • +
    • Coverage: 0/4 Lines (0%)
    • Tests: 0
    • Passed: 0 (0%)
    diff --git a/docs/classes/Akamai_Open_EdgeGrid_Cli/version.html b/docs/classes/Akamai_Open_EdgeGrid_Cli/version.html new file mode 100644 index 0000000..a6804b6 --- /dev/null +++ b/docs/classes/Akamai_Open_EdgeGrid_Cli/version.html @@ -0,0 +1,87 @@ + + + + + phpDox - Test Method + + + + + +
    +
    + +
    + +
    +

    Akamai\Open\EdgeGrid\Cli::version

    +

    +

    +

    Signature

    +
    + public function version() + +
    +

    Test Coverage

    +
    +

    Information

    +
      +
    • Coverage: 0/1 Lines (0%)
    • +
    • Tests: 0
    • +
    • Passed: 0 (0%)
    • +
    +
    +
    +
    +
    + Generated using phpDox 0.8.2-dev - Copyright (C) 2010 - 2015 by Arne Blankerts +
    + + diff --git a/docs/classes/Akamai_Open_EdgeGrid_Client.html b/docs/classes/Akamai_Open_EdgeGrid_Client.html index 0fdfa0f..a4453e3 100644 --- a/docs/classes/Akamai_Open_EdgeGrid_Client.html +++ b/docs/classes/Akamai_Open_EdgeGrid_Client.html @@ -79,7 +79,7 @@

    Synopsis

    extends Client implements LoggerAwareInterface - {
    • // constants
    • const VERSION = "0.4.0-dev";
    • const DEFAULT_REQUEST_TIMEOUT = 10;
    • // members
    • protected static bool|array|resource $staticVerbose = + {
      • // constants
      • const VERSION = "0.4.1";
      • const DEFAULT_REQUEST_TIMEOUT = 10;
      • // members
      • protected static bool|array|resource $staticVerbose = false;
      • protected static bool|resource $staticDebug = false; @@ -159,7 +159,7 @@

        Constants

        VERSION - "0.4.0-dev" + "0.4.1" DEFAULT_REQUEST_TIMEOUT diff --git a/docs/index.html b/docs/index.html index d56b672..a3f1cd8 100644 --- a/docs/index.html +++ b/docs/index.html @@ -34,7 +34,7 @@

        Software Documentation

    Build

    -

    Sat, 24 Oct 2015 20:52:10 -0400

    +

    Fri, 30 Oct 2015 00:38:57 -0400

    VCS Info

    tag:
    @@ -80,7 +80,7 @@

    Structure

    Methods - 75 + 78 @@ -90,13 +90,13 @@

    Structure

    Non-Static Methods - 69 - (92%) + 72 + (92.31%) Static Methods 6 - (8%) + (7.69%) Visibility @@ -105,13 +105,13 @@

    Structure

    Public Method - 53 - (70.67%) + 54 + (69.23%) Non-Public Methods - 22 - (29.33%) + 24 + (30.77%) Functions @@ -167,28 +167,28 @@

    Size

    - + - - + + - - + + - - + + - - + + @@ -203,7 +203,7 @@

    Size

    - + @@ -213,7 +213,7 @@

    Size

    - +
    Lines of Code (LOC)51504735
    Comment Lines of Code (CLOC)1530(29.71%)989(20.89%)
    Non-Comment Lines of Code (NCLOC)3620(70.29%)3746(79.11%)
    Logical Lines of Code (LLOC)1187(23.05%)1226(25.89%)
    Classes444(37.41%)483(39.4%)
    Average Class Length
    Functions 693(58.38%)(56.53%)
    Average Function Length
    Not in classes or functions 50(4.21%)(4.08%)
    @@ -222,7 +222,7 @@

    Complexity

    - + @@ -257,33 +257,33 @@

    Dependencies

    - + - - + + - + - + - - + + - +
    Cyclomatic Complexity / LLOC0.150.16
    Attribute Accesses183193
    Non-Static170(92.9%)180(93.26%)
    Static 13(7.1%)(6.74%)
    Method Calls743753
    Non-Static622(83.71%)632(83.93%)
    Static 121(16.29%)(16.07%)
    diff --git a/docs/source/Cli.php.html b/docs/source/Cli.php.html index 32a8025..1f6a7e5 100644 --- a/docs/source/Cli.php.html +++ b/docs/source/Cli.php.html @@ -1,3 +1,3 @@ phpDox - Source of Cli.php

    Source of file Cli.php

    - Size: 5,925 Bytes - Last Modified: 2015-10-24T20:33:08-04:00

    /Users/dshafik/src/akamai-open/edgegrid-auth-php/src/Cli.php

    123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
    <?php
    /**
     * Akamai {OPEN} EdgeGrid Auth for PHP
     *
     * Akamai\Open\EdgeGrid\Client wraps GuzzleHttp\Client
     * providing request authentication/signing for Akamai
     * {OPEN} APIs.
     *
     * This client works _identically_ to GuzzleHttp\Client
     *
     * However, if you try to call an Akamai {OPEN} API you *must*
     * first call {@see Akamai\Open\EdgeGrid\Client->setAuth()}.
     *
     * @author Davey Shafik <dshafik@akamai.com>
     * @copyright Copyright 2015 Akamai Technologies, Inc. All rights reserved.
     * @license Apache 2.0
     * @link https://github.com/akamai-open/edgegrid-auth-php
     * @link https://developer.akamai.com
     * @link https://developer.akamai.com/introduction/Client_Auth.html
     */
    namespace Akamai\Open\EdgeGrid;

    class Cli
    {
        /**
         * @var CLImate
         */
        protected $climate;

        public function __construct()
        {
            $this->climate = new \League\CLImate\CLImate();
            $this->climate->description("Akamai {OPEN} Edgegrid Auth for PHP Client");
        }

        public function run()
        {
            $this->parseArguments();
            $this->executeCommand();
        }

        protected function parseArguments()
        {
            $args = [
                'help' => [
                    'longPrefix' => 'help',
                    'prefix' => 'h',
                    'description' => 'Show this help output',
                    'noValue' => true
                ],
                'auth-type' => [
                    'longPrefix' => 'auth-type',
                    'prefix' => 'a',
                    'description' => "{basic, digest, edgegrid}"
                ],
                'auth' => [
                    'longPrefix' => 'auth',
                    'prefix' => 'a',
                    'description' => '.edgerc section name, or user[:password]'
                ],
            ];

            $this->climate->arguments->add($args);

            if ($_SERVER['argc'] == 1) {
                $this->help();
            }

            try {
                $this->climate->arguments->parse($_SERVER['argv']);

                $padding = sizeof($args);
                foreach ($this->climate->arguments->toArray() as $arg) {
                    if ($arg == null) {
                        $padding -= 1;
                    }
                }
                $argSize = sizeof($_SERVER['argv']) - $padding - 1;
                for ($i = 0; $i < $argSize; $i++) {
                    $args['arg-' . $i] = [];
                }
                $this->climate->arguments->add($args);
                $this->climate->arguments->parse($_SERVER['argv']);
            } catch (\Exception $e) {
            }
        }

        protected function executeCommand()
        {
            static $methods = [
                'HEAD',
                'GET',
                'POST',
                'PUT',
                'DELETE'
            ];

            if ($this->climate->arguments->get('help')) {
                $this->help();
            }

            \Akamai\Open\EdgeGrid\Client::setDebug(true);
            \Akamai\Open\EdgeGrid\Client::setVerbose(true);

            $args = $this->climate->arguments->all();
            do {
                $last = array_pop($args);
            } while ($last->value() == null);

            $url = $last->value();

            $client = new Client();

            if ($this->climate->arguments->defined('auth-type')) {
                $auth = $this->climate->arguments->get('auth');
                if ($this->climate->arguments->get('auth-type') == 'edgegrid' ||
                    (!$this->climate->arguments->defined('auth-type') && $url{0} == ':')) {
                    $section = 'default';
                    if ($this->climate->arguments->defined('auth')) {
                        $section = (substr($auth, -1) == ':') ? substr($auth, 0, -1) : $auth;
                    }
                    $client = Client::createFromEdgeRcFile($section);
                }

                if (in_array($this->climate->arguments->get('auth-type'), ['basic', 'digest'])) {
                    if (!$this->climate->arguments->defined('auth') || $this->climate->arguments->get('auth') === null) {
                        $this->help();
                    }

                    $auth = [
                        $auth,
                        null,
                        $this->climate->arguments->get('auth-type')
                    ];

                    if (strpos(':', $auth[0]) !== false) {
                        list($auth[0], $auth[1]) = explode(':', $auth[0]);
                    }

                    $client = new Client(['auth' => $auth]);
                }
            }

            $method = 'GET';

            if ($url{0} == ':') {
                $url = substr($url, 1);
            }

            $options = [];
            $body = [];

            foreach ($args as $arg) {
                if (strpos($arg->name(), 'arg-') !== false) {
                    if (in_array(strtoupper($arg->value()), $methods)) {
                        $method = $arg->value();
                        continue;
                    }

                    $matches = [];
                    if (preg_match('/^(?<key>.*?):=(?<value>.*?)$/', $arg->value(), $matches)) {
                        $body[$matches['key']] = json_decode($matches['value']);
                        continue;
                    }

                    if (preg_match('/^(?<header>.*?):(?<value>.*?)$/', $arg->value(), $matches)) {
                        $options['headers'][$matches['header']] = $matches['value'];
                        continue;
                    }

                    if (preg_match('/^(?<key>.*?)=(?<value>.*?)$/', $arg->value(), $matches)) {
                        $body[$matches['key']] = $matches['value'];
                    }
                }
            }

            if (sizeof($body)) {
                if (!isset($options['headers']['Content-Type'])) {
                    $options['headers']['Content-Type'] = 'application/json';
                }
                if (!isset($options['headers']['Accept'])) {
                    $options['headers']['Accept'] = 'application/json';
                }
                $options['body'] = json_encode($body);
            }

            $client->request($method, $url, $options);
        }

        public function help()
        {
            $this->climate->usage($_SERVER['argv']);
            exit;
        }
    }

    Generated using phpDox 0.8.2-dev - Copyright (C) 2010 - 2015 by Arne Blankerts
    + Size: 9,935 Bytes - Last Modified: 2015-10-29T23:46:38-04:00

    /Users/dshafik/src/akamai-open/edgegrid-auth-php/src/Cli.php

    123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
    <?php
    /**
     * Akamai {OPEN} EdgeGrid Auth for PHP
     *
     * Akamai\Open\EdgeGrid\Client wraps GuzzleHttp\Client
     * providing request authentication/signing for Akamai
     * {OPEN} APIs.
     *
     * This client works _identically_ to GuzzleHttp\Client
     *
     * However, if you try to call an Akamai {OPEN} API you *must*
     * first call {@see Akamai\Open\EdgeGrid\Client->setAuth()}.
     *
     * @author Davey Shafik <dshafik@akamai.com>
     * @copyright Copyright 2015 Akamai Technologies, Inc. All rights reserved.
     * @license Apache 2.0
     * @link https://github.com/akamai-open/edgegrid-auth-php
     * @link https://developer.akamai.com
     * @link https://developer.akamai.com/introduction/Client_Auth.html
     */
    namespace Akamai\Open\EdgeGrid;

    class Cli
    {
        /**
         * @var \League\CLImate\CLImate
         */
        protected $climate;

        public function __construct()
        {
            $this->climate = new \League\CLImate\CLImate();
        }

        public function run()
        {
            if ($this->parseArguments()) {
                $this->executeCommand();
            }
        }

        protected function parseArguments()
        {
            $args = $this->getNamedArgs();

            $this->climate->arguments->add($args);

            if ($_SERVER['argc'] == 1) {
                $this->help();
                return false;
            }

            if ($this->climate->arguments->defined('help')) {
                $this->help();
                return;
            }

            if ($this->climate->arguments->defined('version')) {
                echo $this->version();
                return;
            }

            try {
                $this->climate->arguments->parse($_SERVER['argv']);

                $padding = sizeof($args);
                foreach ($this->climate->arguments->toArray() as $arg) {
                    if ($arg == null) {
                        $padding -= 1;
                    }
                }
                $argSize = sizeof($_SERVER['argv']) - $padding - 1;
                for ($i = 0; $i < $argSize; $i++) {
                    $args['arg-' . $i] = [];
                }
                $this->climate->arguments->add($args);
                $this->climate->arguments->parse($_SERVER['argv']);
            } catch (\Exception $e) {
            }

            return true;
        }

        protected function executeCommand()
        {
            static $methods = [
                'HEAD',
                'GET',
                'POST',
                'PUT',
                'DELETE'
            ];

            \Akamai\Open\EdgeGrid\Client::setDebug(true);
            \Akamai\Open\EdgeGrid\Client::setVerbose(true);

            $args = $this->climate->arguments->all();
            $client = new Client();

            if ($this->climate->arguments->defined('auth-type')) {
                $auth = $this->climate->arguments->get('auth');
                if ($this->climate->arguments->get('auth-type') == 'edgegrid' ||
                    (!$this->climate->arguments->defined('auth-type'))) {
                    $section = 'default';
                    if ($this->climate->arguments->defined('auth')) {
                        $section = (substr($auth, -1) == ':') ? substr($auth, 0, -1) : $auth;
                    }
                    $client = Client::createFromEdgeRcFile($section);
                }

                if (in_array($this->climate->arguments->get('auth-type'), ['basic', 'digest'])) {
                    if (!$this->climate->arguments->defined('auth') || $this->climate->arguments->get('auth') === null) {
                        $this->help();
                        return;
                    }

                    $auth = [
                        $auth,
                        null,
                        $this->climate->arguments->get('auth-type')
                    ];

                    if (strpos(':', $auth[0]) !== false) {
                        list($auth[0], $auth[1]) = explode(':', $auth[0]);
                    }

                    $client = new Client(['auth' => $auth]);
                }
            }

            $method = 'GET';
            $options = [];
            $body = [];

            foreach ($args as $arg) {
                $value = $arg->value();
                if (empty($value) || is_bool($value) || $arg->longPrefix()) {
                    continue;
                }

                if (in_array(strtoupper($value), $methods)) {
                    $method = $arg->value();
                    continue;
                }

                if (!isset($url) && preg_match('@^(http(s?)://|:).*$@', trim($value))) {
                    $url = $value;

                    if ($url{0} == ':') {
                        $url = substr($url, 1);
                    }

                    continue;
                }

                $matches = [];
                if (preg_match('/^(?<key>.*?):=(?<file>@?)(?<value>.*?)$/', $value, $matches)) {
                    if (!$value = $this->getArgValue($matches)) {
                        return false;
                    }

                    $body[$matches['key']] = json_decode($value);
                    continue;
                }

                if (preg_match('/^(?<header>.*?):(?<value>.*?)$/', $value, $matches)
                    && !preg_match('@^http(s?)://@', $value)) {
                    $options['headers'][$matches['header']] = $matches['value'];
                    continue;
                }

                if (preg_match('/^(?<key>.*?)=(?<file>@?)(?<value>.*?)$/', $value, $matches)) {
                    if (!$value = $this->getArgValue($matches)) {
                        return false;
                    }

                    $body[$matches['key']] = $matches['value'];
                    continue;
                }

                if (!isset($url)) {
                    $url = $value;
                    continue;
                }

                $this->help();
                $this->climate->error("Unknown argument: " . $value);

                return false;
            }

            $stdin = '';
            $fp = fopen('php://stdin', 'r');
            if ($fp) {
                stream_set_blocking($fp, false);
                $stdin = fgets($fp);
                if (!empty(trim($stdin))) {
                    while (!feof($fp)) {
                        $stdin .= fgets($fp);
                    }
                    fclose($fp);
                }
                $stdin = rtrim($stdin);
            }

            if (!empty($stdin) && !empty($body)) {
                $this->help();
                $this->climate->error(
                    "error: Request body (from stdin or a file) and request data (key=value) cannot be mixed."
                );
                return;
            }

            if (!empty($stdin)) {
                $body = $stdin;
            }

            if (sizeof($body) && !$this->climate->arguments->defined('form')) {
                if (!isset($options['headers']['Content-Type'])) {
                    $options['headers']['Content-Type'] = 'application/json';
                }
                if (!isset($options['headers']['Accept'])) {
                    $options['headers']['Accept'] = 'application/json';
                }
                $options['body'] = (!is_string($body)) ? json_encode($body) : $body;
            }

            if (sizeof($body) && $this->climate->arguments->defined('form')) {
                if (!isset($options['headers']['Content-Type'])) {
                    $options['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
                }

                $options['body'] = (!is_string($body)) ? http_build_query($body, null, null, PHP_QUERY_RFC1738) : $body;
            }

            $options['allow_redirects'] = false;
            if ($this->climate->arguments->defined('follow')) {
                $options['allow_redirects'] = true;
            }

            return $client->request($method, $url, $options);
        }

        public function help()
        {
            $arguments = new \League\CLImate\Argument\Manager();
            $arguments->description("Akamai {OPEN} Edgegrid Auth for PHP Client (v" .Client::VERSION. ')');
            $arguments->add($this->getNamedArgs());
            $arguments->usage($this->climate, $_SERVER['argv']);
            return;
        }

        public function version()
        {
            return Client::VERSION;
        }

        /**
         * @return array
         */
        protected function getNamedArgs()
        {
            $args = [
                'help' => [
                    'longPrefix' => 'help',
                    'prefix' => 'h',
                    'description' => 'Show this help output',
                    'noValue' => true
                ],
                'auth-type' => [
                    'longPrefix' => 'auth-type',
                    'description' => "{basic, digest, edgegrid}"
                ],
                'auth' => [
                    'longPrefix' => 'auth',
                    'prefix' => 'a',
                    'description' => '.edgerc section name, or user[:password]'
                ],
                'json' => [
                    'longPrefix' => 'json',
                    'prefix' => 'j',
                    'description' => '(default) Data items from the command line are serialized as a JSON object.',
                    'noValue' => true
                ],
                'follow' => [
                    'longPrefix' => 'follow',
                    'description' => 'Set this flag if redirects are allowed',
                    'noValue' => true
                ],
                'form' => [
                    'longPrefix' => 'form',
                    'prefix' => 'f',
                    'description' => 'Data items from the command line are serialized as form fields',
                    'noValue' => true
                ],
                'version' => [
                    'longPrefix' => 'version',
                    'description' => 'Show version',
                    'noValue' => true
                ],
                'METHOD' => [
                    'description' => 'HTTP Method (default: GET)'
                ],
                'URL' => [
                    'required' => true,
                ]
            ];

            return $args;
        }

        protected function getArgValue($matches)
        {
            $value = $matches['value'];
            if (!empty($matches['file'])) {
                if (!file_exists($matches['value']) || !is_readable($matches['value'])) {
                    $this->climate->error("Unable to read input file: " . $matches['value']);
                    return false;
                }
                $value = file_get_contents($matches['value']);
            }

            return $value;
        }
    }

    Generated using phpDox 0.8.2-dev - Copyright (C) 2010 - 2015 by Arne Blankerts
    diff --git a/docs/source/Client.php.html b/docs/source/Client.php.html index 21692a2..b14b57d 100644 --- a/docs/source/Client.php.html +++ b/docs/source/Client.php.html @@ -1,6 +1,6 @@ phpDox - Source of Client.php

    Source of file Client.php

    - Size: 18,158 Bytes - Last Modified: 2015-10-24T20:48:20-04:00

    /Users/dshafik/src/akamai-open/edgegrid-auth-php/src/Client.php

    123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
    + Size: 18,154 Bytes - Last Modified: 2015-10-29T23:46:38-04:00

    /Users/dshafik/src/akamai-open/edgegrid-auth-php/src/Client.php

    123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
    Covered by 66 test(s):
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #0
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #1
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #2
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #3
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #4
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #5
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #6
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #7
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #8
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #9
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #10
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #11
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #12
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #13
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testCreateFromEdgeRcDefault with data set #0
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testCreateFromEdgeRcDefault with data set #1
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testCreateFromEdgeRcDefault with data set #2
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testCreateFromEdgeRcDefault with data set #3
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testHostnameWithTrailingSlash
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testDefaultTimeout
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testTimeoutOption
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testSetTimeout
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testStaticDebugSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testInstanceDebugSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testDebugOverrideSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testInstanceDebugOptionSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testNonApiCall
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testForceHttps
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #0
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #1
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #2
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #3
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #4
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #5
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #6
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLoggingRedirect
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLoggingDefault
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLoggingRequestHandler
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testSetSimpleLog
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testInstanceDebug
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testStaticDebug
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testDebugOverride
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testInstanceOverrideStream
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testDebugMessages
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testResponseNoDetail
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testResponseNoBody
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testResponseNoJsonBody
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testDebugResponseExceptionNoCode
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testVerboseResponseExceptionWithCode
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testVerboseResponseExceptionWithBody
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testInstanceVerboseSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testInstanceVerboseMultiple
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testStaticVerboseSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testStaticVerboseMultiple
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseOverrideSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseOverrideMultiple
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseRedirect
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseNonJson
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseRequestHandler
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseNoResponse
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseError
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseErrorNonJson
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseMixed
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseResponseExceptionNoCode
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseResponseExceptionWithCode
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseResponseExceptionWithBody
    114
    Covered by 66 test(s): @@ -344,4 +344,4 @@ Covered by 1 test(s):
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLoggingRequestHandler
    633634635
    Covered by 58 test(s): -
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #0
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #1
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #2
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #3
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #4
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #5
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #6
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #7
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #8
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #9
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #10
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #11
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #12
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #13
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testDefaultTimeout
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testTimeoutOption
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testSetTimeout
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testStaticDebugSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testInstanceDebugSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testDebugOverrideSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testInstanceDebugOptionSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testNonApiCall
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #0
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #1
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #2
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #3
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #4
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #5
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #6
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLoggingRedirect
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testSetSimpleLog
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testInstanceDebug
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testStaticDebug
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testDebugOverride
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testInstanceOverrideStream
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testDebugMessages
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testResponseNoDetail
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testResponseNoBody
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testResponseNoJsonBody
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testDebugResponseExceptionNoCode
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testVerboseResponseExceptionWithCode
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testVerboseResponseExceptionWithBody
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testInstanceVerboseSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testInstanceVerboseMultiple
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testStaticVerboseSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testStaticVerboseMultiple
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseOverrideSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseOverrideMultiple
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseRedirect
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseNonJson
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseRequestHandler
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseNoResponse
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseError
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseErrorNonJson
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseMixed
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseResponseExceptionNoCode
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseResponseExceptionWithCode
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseResponseExceptionWithBody
    636637638
    <?php
    /**
     * Akamai {OPEN} EdgeGrid Auth for PHP
     *
     * Akamai\Open\EdgeGrid\Client wraps GuzzleHttp\Client
     * providing request authentication/signing for Akamai
     * {OPEN} APIs.
     *
     * This client works _identically_ to GuzzleHttp\Client
     *
     * However, if you try to call an Akamai {OPEN} API you *must*
     * first call {@see Akamai\Open\EdgeGrid\Client->setAuth()}.
     *
     * @author Davey Shafik <dshafik@akamai.com>
     * @copyright Copyright 2015 Akamai Technologies, Inc. All rights reserved.
     * @license Apache 2.0
     * @link https://github.com/akamai-open/edgegrid-auth-php
     * @link https://developer.akamai.com
     * @link https://developer.akamai.com/introduction/Client_Auth.html
     */
    namespace Akamai\Open\EdgeGrid;

    use Akamai\Open\EdgeGrid\Authentication;
    use Akamai\Open\EdgeGrid\Handler\Authentication as AuthenticationHandler;
    use Akamai\Open\EdgeGrid\Handler\Debug as DebugHandler;
    use Akamai\Open\EdgeGrid\Handler\Verbose as VerboseHandler;

    /**
     * Akamai {OPEN} EdgeGrid Client for PHP
     *
     * Akamai {OPEN} EdgeGrid Client for PHP. Based on
     * [Guzzle](http://guzzlephp.org).
     *
     * @package Akamai {OPEN} EdgeGrid Client
     */
    class Client extends \GuzzleHttp\Client implements \Psr\Log\LoggerAwareInterface
    {
        const VERSION = "0.4.0-dev";

        /**
         * @const int Default Timeout in seconds
         */
        const DEFAULT_REQUEST_TIMEOUT = 10;

        /**
         * @var bool|array|resource Whether verbose mode is enabled
         *
         * - true - Use STDOUT
         * - array - output/error streams (different)
         * - resource - output/error stream (same)
         */
        protected static $staticVerbose = false;

        /**
         * @var bool|resource Whether debug mode is enabled
         */
        protected static $staticDebug = false;

        /**
         * @var \Akamai\Open\EdgeGrid\Authentication
         */
        protected $authentication;

        /**
         * @var \Akamai\Open\EdgeGrid\Handler\Verbose
         */
        protected $verboseHandler;

        /**
         * @var \Akamai\Open\EdgeGrid\Handler\Debug
         */
        protected $debugHandler;

        /**
         * @var bool|array|resource Whether verbose mode is enabled
         *
         * - true - Use STDOUT
         * - array - output/error streams (different)
         * - resource - output/error stream (same)
         */
        protected $verbose = false;

        /**
         * @var bool|resource Whether debugging is enabled
         */
        protected $debug = false;

        /**
         * @var bool Whether to override the static verbose setting
         */
        protected $verboseOverride = false;

        /**
         * @var bool Whether to override the static debug setting
         */
        protected $debugOverride = false;

        /**
         * @var \Closure Logging Handler
         */
        protected $logger;

        /**
         * \GuzzleHttp\Client-compatible constructor
         *
         * @param array $config Config options array
         * @param Authentication|null $authentication
         */
        public function __construct(
            $config = [],
            Authentication $authentication = null
        ) {
            $config = $this->setAuthenticationHandler($config, $authentication);
            $config = $this->setBasicOptions($config);
            $config['headers']['User-Agent'] = 'Akamai-Open-Edgegrid-PHP/' .
                self::VERSION . ' ' . \GuzzleHttp\default_user_agent();

            parent::__construct($config);
        }

        /**
         * Make an Asynchronous request
         *
         * @param string $method
         * @param string $uri
         * @param array $options
         * @return \GuzzleHttp\Promise\PromiseInterface
         * @throws \GuzzleHttp\Exception\GuzzleException
         */
        public function requestAsync($method, $uri = null, array $options = [])
        {
            $options = $this->setRequestOptions($options);

            $query = parse_url($uri, PHP_URL_QUERY);
            if (!empty($query)) {
                $uri = substr($uri, 0, ((strlen($query)+1)) * -1);
                parse_str($query, $options['query']);
            }

            return parent::requestAsync($method, $uri, $options);
        }

        public function sendAsync(\Psr\Http\Message\RequestInterface $request, array $options = [])
        {
            $options = $this->setRequestOptions($options);

            return parent::sendAsync($request, $options);
        }


        /**
         * Set Akamai {OPEN} Authentication Credentials
         *
         * @param string $client_token
         * @param string $client_secret
         * @param string $access_token
         * @return $this
         */
        public function setAuth($client_token, $client_secret, $access_token)
        {
            $this->authentication->setAuth($client_token, $client_secret, $access_token);

            return $this;
        }

        /**
         * Specify the headers to include when signing the request
         *
         * This is specified by the API, currently no APIs use this
         * feature.
         *
         * @param array $headers
         * @return $this
         */
        public function setHeadersToSign(array $headers)
        {
            $this->authentication->setHeadersToSign($headers);

            return $this;
        }

        /**
         * Set the max body size
         *
         * @param int $max_body_size
         * @return $this
         */
        public function setMaxBodySize($max_body_size)
        {
            $this->authentication->setMaxBodySize($max_body_size);

            return $this;
        }

        /**
         * Set Request Host
         *
         * @param string $host
         * @return $this
         */
        public function setHost($host)
        {
            if (substr($host, -1) == '/') {
                $host = substr($host, 0, -1);
            }

            $headers = $this->getConfig('headers');
            $headers['Host'] = $host;
            $this->setConfigOption('headers', $headers);

            if (strpos('/', $host) === false) {
                $host = 'https://' . $host;
            }
            $this->setConfigOption('base_uri', $host);

            return $this;
        }

        /**
         * Set the HTTP request timeout
         *
         * @param int $timeout_in_seconds
         * @return $this
         */
        public function setTimeout($timeout_in_seconds)
        {
            $this->setConfigOption('timeout', $timeout_in_seconds);

            return $this;
        }

        /**
         * Print formatted JSON responses to output
         *
         * @param bool|resource $enable
         * @return $this
         */
        public function setInstanceVerbose($enable)
        {
            $this->verboseOverride = true;
            $this->verbose = $enable;
            return $this;
        }

        /**
         * Print HTTP requests/responses to output
         *
         * @param bool|resource $enable
         * @return $this
         */
        public function setInstanceDebug($enable)
        {
            $this->debugOverride = true;
            $this->debug = $enable;
            return $this;
        }

        /**
         * Set a PSR-3 compatible logger (or use monolog by default)
         *
         * @param \Psr\Log\LoggerInterface $logger
         * @param string $messageFormat Message format
         * @return $this
         */
        public function setLogger(
            \Psr\Log\LoggerInterface $logger = null,
            $messageFormat = \GuzzleHttp\MessageFormatter::CLF
        ) {
            if ($logger === null) {
                $handler = new \Monolog\Handler\ErrorLogHandler(\Monolog\Handler\ErrorLogHandler::SAPI);
                $handler->setFormatter(new \Monolog\Formatter\LineFormatter("%message%"));
                $logger = new \Monolog\Logger('HTTP Log', [$handler]);
            }

            $formatter = new \GuzzleHttp\MessageFormatter($messageFormat);

            $handler = \GuzzleHttp\Middleware::log($logger, $formatter);
            $this->logger = $handler;

            $handlerStack = $this->getConfig('handler');
            $this->setLogHandler($handlerStack, $handler);

            return $this;
        }

        /**
         * Add logger using a given filename/format
         *
         * @param string $filename
         * @param string $format
         */
        public function setSimpleLog($filename, $format = "{code}")
        {
            if ($this->logger && !($this->logger instanceof \Monolog\Logger)) {
                return false;
            }

            $handler = new \Monolog\Handler\StreamHandler($filename);
            $handler->setFormatter(new \Monolog\Formatter\LineFormatter("%message%"));
            $log = new \Monolog\Logger('HTTP Log', [$handler]);

            return $this->setLogger($log, $format);
        }

        /**
         * Factory method to create a client using credentials from `.edgerc`
         *
         * Automatically checks your HOME directory, and the current working
         * directory for credentials, if no path is supplied.
         *
         * @param string $section Credential section to use
         * @param string $path Path to .edgerc credentials file
         * @param array $config Options to pass to the constructor/guzzle
         * @return \Akamai\Open\EdgeGrid\Client
         */
        public static function createFromEdgeRcFile($section = 'default', $path = null, $config = [])
        {
            $auth = \Akamai\Open\EdgeGrid\Authentication::createFromEdgeRcFile($section, $path);

            if ($host = $auth->getHost()) {
                $config['base_uri'] = 'https://' . $host;
            }

            $client = new static($config, $auth);
            return $client;
        }

        /**
         * Print HTTP requests/responses to STDOUT
         *
         * @param bool|resource $enable
         */
        public static function setDebug($enable)
        {
            self::$staticDebug = $enable;
        }

        /**
         * Print formatted JSON responses to STDOUT
         *
         * @param bool|resource $enable
         */
        public static function setVerbose($enable)
        {
            self::$staticVerbose = $enable;
        }

        /**
         * Handle debug option
         *
         * @return bool|resource
         */
        protected function getDebugOption($config)
        {
            if (isset($config['debug'])) {
                return ($config['debug'] === true) ? STDERR : $config['debug'];
            }

            if (($this->debugOverride && $this->debug)) {
                return ($this->debug === true) ? STDERR : $this->debug;
            } elseif ((!$this->debugOverride && static::$staticDebug)) {
                return (static::$staticDebug === true) ? STDERR : static::$staticDebug;
            }

            return false;
        }

        /**
         * Debugging status for the current request
         *
         * @return bool|resource
         */
        protected function isDebug()
        {
            if (($this->debugOverride && !$this->debug) || (!($this->debugOverride) && !static::$staticDebug)) {
                return false;
            }

            if ($this->debugOverride && $this->debug) {
                return $this->debug;
            }

            return static::$staticDebug;
        }

        /**
         * Verbose status for the current request
         *
         * @return array|bool|resource
         */
        protected function isVerbose()
        {
            if (($this->verboseOverride && !$this->verbose) || (!($this->verboseOverride) && !static::$staticVerbose)) {
                return false;
            }

            if ($this->verboseOverride && $this->verbose) {
                return $this->verbose;
            }

            return static::$staticVerbose;
        }

        /**
         * Set the Authentication instance
         *
         * @param Authentication|null $authentication
         */
        protected function setAuthentication(array $config, Authentication $authentication = null)
        {
            $this->authentication = $authentication;
            if ($authentication === null) {
                $this->authentication = new Authentication();
            }

            if (isset($config['timestamp'])) {
                $this->authentication->setTimestamp($config['timestamp']);
            }

            if (isset($config['nonce'])) {
                $this->authentication->setNonce($config['nonce']);
            }
        }

        /**
         * Set the Authentication Handler
         *
         * @param array $config
         * @param Authentication|null $authentication
         * @return array
         */
        protected function setAuthenticationHandler($config, Authentication $authentication = null)
        {
            $this->setAuthentication($config, $authentication);

            $authenticationHandler = new AuthenticationHandler();
            $authenticationHandler->setSigner($this->authentication);
            if (!isset($config['handler'])) {
                $config['handler'] = \GuzzleHttp\HandlerStack::create();
            }
            try {
                if (!($config['handler'] instanceof \GuzzleHttp\HandlerStack)) {
                    $config['handler'] = \GuzzleHttp\HandlerStack::create($config['handler']);
                }
                $config['handler']->before("history", $authenticationHandler, 'authentication');
            } catch (\InvalidArgumentException $e) {
                // history middleware not added yet
                $config['handler']->push($authenticationHandler, 'authentication');
            }
            return $config;
        }

        /**
         * @param $config
         * @return mixed
         */
        protected function setBasicOptions($config)
        {
            if (!isset($config['timeout'])) {
                $config['timeout'] = static::DEFAULT_REQUEST_TIMEOUT;
            }

            if (isset($config['base_uri']) && strpos($config['base_uri'], 'http') === false) {
                $config['base_uri'] = 'https://' . $config['base_uri'];
                return $config;
            }
            return $config;
        }

        /**
         * Set values on the private \GuzzleHttp\Client->config
         *
         * This is a terrible hack, and illustrates why making
         * anything private makes it difficult to extend, and impossible
         * when there is no setter.
         *
         * @param string $what Config option to set
         * @param mixed $value Value to set the option to
         * @return void
         */
        protected function setConfigOption($what, $value)
        {
            $closure = function () use ($what, $value) {
                /* @var $this \GuzzleHttp\Client */
                $this->config[$what] = $value;
            };

            $closure = $closure->bindTo($this, \GuzzleHttp\Client::CLASS);
            $closure();
        }

        /**
         * Add the Debug handler to the HandlerStack
         *
         * @param array $options Guzzle Options
         * @param bool|resource|null $fp Stream to write to
         * @return array
         */
        protected function setDebugHandler($options, $fp = null)
        {
            try {
                if (is_bool($fp)) {
                    $fp = null;
                }

                $handler = $this->getConfig('handler');
                // if we have a default handler, and we've already created a DebugHandler
                // we can bail out now (or we will add another one to the stack)
                if ($handler && $this->debugHandler) {
                    return $options;
                }

                if (isset($options['handler'])) {
                    $handler = $options['handler'];
                }

                if ($handler === null) {
                    $handler = \GuzzleHttp\HandlerStack::create();
                }

                if (!$this->debugHandler) {
                    $this->debugHandler = new DebugHandler($fp);
                }

                $handler->after("allow_redirects", $this->debugHandler, "debug");
            } catch (\InvalidArgumentException $e) {
                $handler->push($this->debugHandler, "debug");
            }

            $options['handler'] = $handler;

            return $options;
        }

        /**
         * Add the Log handler to the HandlerStack
         *
         * @param \GuzzleHttp\HandlerStack $handlerStack
         * @param callable $logHandler
         */
        protected function setLogHandler(\GuzzleHttp\HandlerStack $handlerStack, callable $logHandler)
        {
            try {
                $handlerStack->after("history", $logHandler, "logger");
            } catch (\InvalidArgumentException $e) {
                try {
                    $handlerStack->before("allow_redirects", $logHandler, "logger");
                } catch (\InvalidArgumentException $e) {
                    $handlerStack->push($logHandler, "logger");
                }
            }

            return $this;
        }

        /**
         * Add the Verbose handler to the HandlerStack
         *
         * @param array $options Guzzle Options
         * @param bool|resource|array|null $fp Stream to write to
         * @return array
         */
        protected function setVerboseHandler($options, $fp = null)
        {
            try {
                if (is_bool($fp) || $fp === null) {
                    $fp = ['outputStream' => null, 'errorStream' => null];
                } elseif (!is_array($fp)) {
                    $fp = ['outputStream' => $fp, 'errorStream' => $fp];
                }

                $handler = $this->getConfig('handler');
                // if we have a default handler, and we've already created a VerboseHandler
                // we can bail out now (or we will add another one to the stack)
                if ($handler && $this->verboseHandler) {
                    return $options;
                }

                if (isset($options['handler'])) {
                    $handler = $options['handler'];
                }

                if ($handler === null) {
                    $handler = \GuzzleHttp\HandlerStack::create();
                }

                if (!$this->verboseHandler) {
                    $this->verboseHandler = new VerboseHandler(array_shift($fp), array_shift($fp));
                }

                $handler->after("allow_redirects", $this->verboseHandler, "verbose");
            } catch (\InvalidArgumentException $e) {
                $handler->push($this->verboseHandler, "verbose");
            }

            $options['handler'] = $handler;

            return $options;
        }

        /**
         * @param array $options
         * @return array
         */
        protected function setRequestOptions(array $options)
        {
            if (isset($options['timestamp'])) {
                $this->authentication->setTimestamp($options['timestamp']);
            } elseif (!$this->getConfig('timestamp')) {
                $this->authentication->setTimestamp();
            }

            if (isset($options['nonce'])) {
                $this->authentication->setNonce($options['nonce']);
            }

            if (isset($options['handler'])) {
                $options = $this->setAuthenticationHandler($options, $this->authentication);
            }

            if ($fp = $this->isVerbose()) {
                $options = $this->setVerboseHandler($options, $fp);
            }

            $options['debug'] = $this->getDebugOption($options);
            if ($fp = $this->isDebug()) {
                $options = $this->setDebugHandler($options, $fp);
            }

            if ($this->logger && isset($options['handler'])) {
                $this->setLogHandler($options['handler'], $this->logger);
                return $options;
            }

            return $options;
        }
    }

    Generated using phpDox 0.8.2-dev - Copyright (C) 2010 - 2015 by Arne Blankerts
    +
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #0
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #1
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #2
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #3
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #4
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #5
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #6
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #7
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #8
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #9
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #10
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #11
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #12
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testMakeAuthHeaderPsr7 with data set #13
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testDefaultTimeout
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testTimeoutOption
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testSetTimeout
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testStaticDebugSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testInstanceDebugSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testDebugOverrideSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testInstanceDebugOptionSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testNonApiCall
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #0
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #1
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #2
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #3
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #4
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #5
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLogging with data set #6
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testLoggingRedirect
    • Akamai\Open\EdgeGrid\Tests\Handler\AuthenticationTest::testSetSimpleLog
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testInstanceDebug
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testStaticDebug
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testDebugOverride
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testInstanceOverrideStream
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testDebugMessages
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testResponseNoDetail
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testResponseNoBody
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testResponseNoJsonBody
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testDebugResponseExceptionNoCode
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testVerboseResponseExceptionWithCode
    • Akamai\Open\EdgeGrid\Tests\Handler\DebugTest::testVerboseResponseExceptionWithBody
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testInstanceVerboseSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testInstanceVerboseMultiple
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testStaticVerboseSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testStaticVerboseMultiple
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseOverrideSingle
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseOverrideMultiple
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseRedirect
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseNonJson
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseRequestHandler
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseNoResponse
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseError
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseErrorNonJson
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseMixed
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseResponseExceptionNoCode
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseResponseExceptionWithCode
    • Akamai\Open\EdgeGrid\Tests\Handler\VerboseTest::testVerboseResponseExceptionWithBody
    636637638
    <?php
    /**
     * Akamai {OPEN} EdgeGrid Auth for PHP
     *
     * Akamai\Open\EdgeGrid\Client wraps GuzzleHttp\Client
     * providing request authentication/signing for Akamai
     * {OPEN} APIs.
     *
     * This client works _identically_ to GuzzleHttp\Client
     *
     * However, if you try to call an Akamai {OPEN} API you *must*
     * first call {@see Akamai\Open\EdgeGrid\Client->setAuth()}.
     *
     * @author Davey Shafik <dshafik@akamai.com>
     * @copyright Copyright 2015 Akamai Technologies, Inc. All rights reserved.
     * @license Apache 2.0
     * @link https://github.com/akamai-open/edgegrid-auth-php
     * @link https://developer.akamai.com
     * @link https://developer.akamai.com/introduction/Client_Auth.html
     */
    namespace Akamai\Open\EdgeGrid;

    use Akamai\Open\EdgeGrid\Authentication;
    use Akamai\Open\EdgeGrid\Handler\Authentication as AuthenticationHandler;
    use Akamai\Open\EdgeGrid\Handler\Debug as DebugHandler;
    use Akamai\Open\EdgeGrid\Handler\Verbose as VerboseHandler;

    /**
     * Akamai {OPEN} EdgeGrid Client for PHP
     *
     * Akamai {OPEN} EdgeGrid Client for PHP. Based on
     * [Guzzle](http://guzzlephp.org).
     *
     * @package Akamai {OPEN} EdgeGrid Client
     */
    class Client extends \GuzzleHttp\Client implements \Psr\Log\LoggerAwareInterface
    {
        const VERSION = "0.4.1";

        /**
         * @const int Default Timeout in seconds
         */
        const DEFAULT_REQUEST_TIMEOUT = 10;

        /**
         * @var bool|array|resource Whether verbose mode is enabled
         *
         * - true - Use STDOUT
         * - array - output/error streams (different)
         * - resource - output/error stream (same)
         */
        protected static $staticVerbose = false;

        /**
         * @var bool|resource Whether debug mode is enabled
         */
        protected static $staticDebug = false;

        /**
         * @var \Akamai\Open\EdgeGrid\Authentication
         */
        protected $authentication;

        /**
         * @var \Akamai\Open\EdgeGrid\Handler\Verbose
         */
        protected $verboseHandler;

        /**
         * @var \Akamai\Open\EdgeGrid\Handler\Debug
         */
        protected $debugHandler;

        /**
         * @var bool|array|resource Whether verbose mode is enabled
         *
         * - true - Use STDOUT
         * - array - output/error streams (different)
         * - resource - output/error stream (same)
         */
        protected $verbose = false;

        /**
         * @var bool|resource Whether debugging is enabled
         */
        protected $debug = false;

        /**
         * @var bool Whether to override the static verbose setting
         */
        protected $verboseOverride = false;

        /**
         * @var bool Whether to override the static debug setting
         */
        protected $debugOverride = false;

        /**
         * @var \Closure Logging Handler
         */
        protected $logger;

        /**
         * \GuzzleHttp\Client-compatible constructor
         *
         * @param array $config Config options array
         * @param Authentication|null $authentication
         */
        public function __construct(
            $config = [],
            Authentication $authentication = null
        ) {
            $config = $this->setAuthenticationHandler($config, $authentication);
            $config = $this->setBasicOptions($config);
            $config['headers']['User-Agent'] = 'Akamai-Open-Edgegrid-PHP/' .
                self::VERSION . ' ' . \GuzzleHttp\default_user_agent();

            parent::__construct($config);
        }

        /**
         * Make an Asynchronous request
         *
         * @param string $method
         * @param string $uri
         * @param array $options
         * @return \GuzzleHttp\Promise\PromiseInterface
         * @throws \GuzzleHttp\Exception\GuzzleException
         */
        public function requestAsync($method, $uri = null, array $options = [])
        {
            $options = $this->setRequestOptions($options);

            $query = parse_url($uri, PHP_URL_QUERY);
            if (!empty($query)) {
                $uri = substr($uri, 0, ((strlen($query)+1)) * -1);
                parse_str($query, $options['query']);
            }

            return parent::requestAsync($method, $uri, $options);
        }

        public function sendAsync(\Psr\Http\Message\RequestInterface $request, array $options = [])
        {
            $options = $this->setRequestOptions($options);

            return parent::sendAsync($request, $options);
        }


        /**
         * Set Akamai {OPEN} Authentication Credentials
         *
         * @param string $client_token
         * @param string $client_secret
         * @param string $access_token
         * @return $this
         */
        public function setAuth($client_token, $client_secret, $access_token)
        {
            $this->authentication->setAuth($client_token, $client_secret, $access_token);

            return $this;
        }

        /**
         * Specify the headers to include when signing the request
         *
         * This is specified by the API, currently no APIs use this
         * feature.
         *
         * @param array $headers
         * @return $this
         */
        public function setHeadersToSign(array $headers)
        {
            $this->authentication->setHeadersToSign($headers);

            return $this;
        }

        /**
         * Set the max body size
         *
         * @param int $max_body_size
         * @return $this
         */
        public function setMaxBodySize($max_body_size)
        {
            $this->authentication->setMaxBodySize($max_body_size);

            return $this;
        }

        /**
         * Set Request Host
         *
         * @param string $host
         * @return $this
         */
        public function setHost($host)
        {
            if (substr($host, -1) == '/') {
                $host = substr($host, 0, -1);
            }

            $headers = $this->getConfig('headers');
            $headers['Host'] = $host;
            $this->setConfigOption('headers', $headers);

            if (strpos('/', $host) === false) {
                $host = 'https://' . $host;
            }
            $this->setConfigOption('base_uri', $host);

            return $this;
        }

        /**
         * Set the HTTP request timeout
         *
         * @param int $timeout_in_seconds
         * @return $this
         */
        public function setTimeout($timeout_in_seconds)
        {
            $this->setConfigOption('timeout', $timeout_in_seconds);

            return $this;
        }

        /**
         * Print formatted JSON responses to output
         *
         * @param bool|resource $enable
         * @return $this
         */
        public function setInstanceVerbose($enable)
        {
            $this->verboseOverride = true;
            $this->verbose = $enable;
            return $this;
        }

        /**
         * Print HTTP requests/responses to output
         *
         * @param bool|resource $enable
         * @return $this
         */
        public function setInstanceDebug($enable)
        {
            $this->debugOverride = true;
            $this->debug = $enable;
            return $this;
        }

        /**
         * Set a PSR-3 compatible logger (or use monolog by default)
         *
         * @param \Psr\Log\LoggerInterface $logger
         * @param string $messageFormat Message format
         * @return $this
         */
        public function setLogger(
            \Psr\Log\LoggerInterface $logger = null,
            $messageFormat = \GuzzleHttp\MessageFormatter::CLF
        ) {
            if ($logger === null) {
                $handler = new \Monolog\Handler\ErrorLogHandler(\Monolog\Handler\ErrorLogHandler::SAPI);
                $handler->setFormatter(new \Monolog\Formatter\LineFormatter("%message%"));
                $logger = new \Monolog\Logger('HTTP Log', [$handler]);
            }

            $formatter = new \GuzzleHttp\MessageFormatter($messageFormat);

            $handler = \GuzzleHttp\Middleware::log($logger, $formatter);
            $this->logger = $handler;

            $handlerStack = $this->getConfig('handler');
            $this->setLogHandler($handlerStack, $handler);

            return $this;
        }

        /**
         * Add logger using a given filename/format
         *
         * @param string $filename
         * @param string $format
         */
        public function setSimpleLog($filename, $format = "{code}")
        {
            if ($this->logger && !($this->logger instanceof \Monolog\Logger)) {
                return false;
            }

            $handler = new \Monolog\Handler\StreamHandler($filename);
            $handler->setFormatter(new \Monolog\Formatter\LineFormatter("%message%"));
            $log = new \Monolog\Logger('HTTP Log', [$handler]);

            return $this->setLogger($log, $format);
        }

        /**
         * Factory method to create a client using credentials from `.edgerc`
         *
         * Automatically checks your HOME directory, and the current working
         * directory for credentials, if no path is supplied.
         *
         * @param string $section Credential section to use
         * @param string $path Path to .edgerc credentials file
         * @param array $config Options to pass to the constructor/guzzle
         * @return \Akamai\Open\EdgeGrid\Client
         */
        public static function createFromEdgeRcFile($section = 'default', $path = null, $config = [])
        {
            $auth = \Akamai\Open\EdgeGrid\Authentication::createFromEdgeRcFile($section, $path);

            if ($host = $auth->getHost()) {
                $config['base_uri'] = 'https://' . $host;
            }

            $client = new static($config, $auth);
            return $client;
        }

        /**
         * Print HTTP requests/responses to STDOUT
         *
         * @param bool|resource $enable
         */
        public static function setDebug($enable)
        {
            self::$staticDebug = $enable;
        }

        /**
         * Print formatted JSON responses to STDOUT
         *
         * @param bool|resource $enable
         */
        public static function setVerbose($enable)
        {
            self::$staticVerbose = $enable;
        }

        /**
         * Handle debug option
         *
         * @return bool|resource
         */
        protected function getDebugOption($config)
        {
            if (isset($config['debug'])) {
                return ($config['debug'] === true) ? STDERR : $config['debug'];
            }

            if (($this->debugOverride && $this->debug)) {
                return ($this->debug === true) ? STDERR : $this->debug;
            } elseif ((!$this->debugOverride && static::$staticDebug)) {
                return (static::$staticDebug === true) ? STDERR : static::$staticDebug;
            }

            return false;
        }

        /**
         * Debugging status for the current request
         *
         * @return bool|resource
         */
        protected function isDebug()
        {
            if (($this->debugOverride && !$this->debug) || (!($this->debugOverride) && !static::$staticDebug)) {
                return false;
            }

            if ($this->debugOverride && $this->debug) {
                return $this->debug;
            }

            return static::$staticDebug;
        }

        /**
         * Verbose status for the current request
         *
         * @return array|bool|resource
         */
        protected function isVerbose()
        {
            if (($this->verboseOverride && !$this->verbose) || (!($this->verboseOverride) && !static::$staticVerbose)) {
                return false;
            }

            if ($this->verboseOverride && $this->verbose) {
                return $this->verbose;
            }

            return static::$staticVerbose;
        }

        /**
         * Set the Authentication instance
         *
         * @param Authentication|null $authentication
         */
        protected function setAuthentication(array $config, Authentication $authentication = null)
        {
            $this->authentication = $authentication;
            if ($authentication === null) {
                $this->authentication = new Authentication();
            }

            if (isset($config['timestamp'])) {
                $this->authentication->setTimestamp($config['timestamp']);
            }

            if (isset($config['nonce'])) {
                $this->authentication->setNonce($config['nonce']);
            }
        }

        /**
         * Set the Authentication Handler
         *
         * @param array $config
         * @param Authentication|null $authentication
         * @return array
         */
        protected function setAuthenticationHandler($config, Authentication $authentication = null)
        {
            $this->setAuthentication($config, $authentication);

            $authenticationHandler = new AuthenticationHandler();
            $authenticationHandler->setSigner($this->authentication);
            if (!isset($config['handler'])) {
                $config['handler'] = \GuzzleHttp\HandlerStack::create();
            }
            try {
                if (!($config['handler'] instanceof \GuzzleHttp\HandlerStack)) {
                    $config['handler'] = \GuzzleHttp\HandlerStack::create($config['handler']);
                }
                $config['handler']->before("history", $authenticationHandler, 'authentication');
            } catch (\InvalidArgumentException $e) {
                // history middleware not added yet
                $config['handler']->push($authenticationHandler, 'authentication');
            }
            return $config;
        }

        /**
         * @param $config
         * @return mixed
         */
        protected function setBasicOptions($config)
        {
            if (!isset($config['timeout'])) {
                $config['timeout'] = static::DEFAULT_REQUEST_TIMEOUT;
            }

            if (isset($config['base_uri']) && strpos($config['base_uri'], 'http') === false) {
                $config['base_uri'] = 'https://' . $config['base_uri'];
                return $config;
            }
            return $config;
        }

        /**
         * Set values on the private \GuzzleHttp\Client->config
         *
         * This is a terrible hack, and illustrates why making
         * anything private makes it difficult to extend, and impossible
         * when there is no setter.
         *
         * @param string $what Config option to set
         * @param mixed $value Value to set the option to
         * @return void
         */
        protected function setConfigOption($what, $value)
        {
            $closure = function () use ($what, $value) {
                /* @var $this \GuzzleHttp\Client */
                $this->config[$what] = $value;
            };

            $closure = $closure->bindTo($this, \GuzzleHttp\Client::CLASS);
            $closure();
        }

        /**
         * Add the Debug handler to the HandlerStack
         *
         * @param array $options Guzzle Options
         * @param bool|resource|null $fp Stream to write to
         * @return array
         */
        protected function setDebugHandler($options, $fp = null)
        {
            try {
                if (is_bool($fp)) {
                    $fp = null;
                }

                $handler = $this->getConfig('handler');
                // if we have a default handler, and we've already created a DebugHandler
                // we can bail out now (or we will add another one to the stack)
                if ($handler && $this->debugHandler) {
                    return $options;
                }

                if (isset($options['handler'])) {
                    $handler = $options['handler'];
                }

                if ($handler === null) {
                    $handler = \GuzzleHttp\HandlerStack::create();
                }

                if (!$this->debugHandler) {
                    $this->debugHandler = new DebugHandler($fp);
                }

                $handler->after("allow_redirects", $this->debugHandler, "debug");
            } catch (\InvalidArgumentException $e) {
                $handler->push($this->debugHandler, "debug");
            }

            $options['handler'] = $handler;

            return $options;
        }

        /**
         * Add the Log handler to the HandlerStack
         *
         * @param \GuzzleHttp\HandlerStack $handlerStack
         * @param callable $logHandler
         */
        protected function setLogHandler(\GuzzleHttp\HandlerStack $handlerStack, callable $logHandler)
        {
            try {
                $handlerStack->after("history", $logHandler, "logger");
            } catch (\InvalidArgumentException $e) {
                try {
                    $handlerStack->before("allow_redirects", $logHandler, "logger");
                } catch (\InvalidArgumentException $e) {
                    $handlerStack->push($logHandler, "logger");
                }
            }

            return $this;
        }

        /**
         * Add the Verbose handler to the HandlerStack
         *
         * @param array $options Guzzle Options
         * @param bool|resource|array|null $fp Stream to write to
         * @return array
         */
        protected function setVerboseHandler($options, $fp = null)
        {
            try {
                if (is_bool($fp) || $fp === null) {
                    $fp = ['outputStream' => null, 'errorStream' => null];
                } elseif (!is_array($fp)) {
                    $fp = ['outputStream' => $fp, 'errorStream' => $fp];
                }

                $handler = $this->getConfig('handler');
                // if we have a default handler, and we've already created a VerboseHandler
                // we can bail out now (or we will add another one to the stack)
                if ($handler && $this->verboseHandler) {
                    return $options;
                }

                if (isset($options['handler'])) {
                    $handler = $options['handler'];
                }

                if ($handler === null) {
                    $handler = \GuzzleHttp\HandlerStack::create();
                }

                if (!$this->verboseHandler) {
                    $this->verboseHandler = new VerboseHandler(array_shift($fp), array_shift($fp));
                }

                $handler->after("allow_redirects", $this->verboseHandler, "verbose");
            } catch (\InvalidArgumentException $e) {
                $handler->push($this->verboseHandler, "verbose");
            }

            $options['handler'] = $handler;

            return $options;
        }

        /**
         * @param array $options
         * @return array
         */
        protected function setRequestOptions(array $options)
        {
            if (isset($options['timestamp'])) {
                $this->authentication->setTimestamp($options['timestamp']);
            } elseif (!$this->getConfig('timestamp')) {
                $this->authentication->setTimestamp();
            }

            if (isset($options['nonce'])) {
                $this->authentication->setNonce($options['nonce']);
            }

            if (isset($options['handler'])) {
                $options = $this->setAuthenticationHandler($options, $this->authentication);
            }

            if ($fp = $this->isVerbose()) {
                $options = $this->setVerboseHandler($options, $fp);
            }

            $options['debug'] = $this->getDebugOption($options);
            if ($fp = $this->isDebug()) {
                $options = $this->setDebugHandler($options, $fp);
            }

            if ($this->logger && isset($options['handler'])) {
                $this->setLogHandler($options['handler'], $this->logger);
                return $options;
            }

            return $options;
        }
    }

    Generated using phpDox 0.8.2-dev - Copyright (C) 2010 - 2015 by Arne Blankerts
    diff --git a/docs/source/Exception/HandlerException/index.html b/docs/source/Exception/HandlerException/index.html index b6b46e0..21476ec 100644 --- a/docs/source/Exception/HandlerException/index.html +++ b/docs/source/Exception/HandlerException/index.html @@ -67,7 +67,7 @@

    Source of Akamai {OPEN} Auth for PHP

    672 Bytes - 2015-10-24T20:32:11-04:00 + 2015-10-29T21:00:58-04:00 diff --git a/docs/source/Exception/SignerException/index.html b/docs/source/Exception/SignerException/index.html index bfbaba4..607b7db 100644 --- a/docs/source/Exception/SignerException/index.html +++ b/docs/source/Exception/SignerException/index.html @@ -67,7 +67,7 @@

    Source of Akamai {OPEN} Auth for PHP

    682 Bytes - 2015-10-24T20:32:11-04:00 + 2015-10-29T21:00:58-04:00 diff --git a/docs/source/Exception/index.html b/docs/source/Exception/index.html index 401f813..8f95f8c 100644 --- a/docs/source/Exception/index.html +++ b/docs/source/Exception/index.html @@ -61,7 +61,7 @@

    Source of Akamai {OPEN} Auth for PHP

    635 Bytes - 2015-10-24T20:32:11-04:00 + 2015-10-29T21:00:58-04:00 @@ -78,7 +78,7 @@

    Source of Akamai {OPEN} Auth for PHP

    636 Bytes - 2015-10-24T20:32:11-04:00 + 2015-10-29T21:00:58-04:00 @@ -95,7 +95,7 @@

    Source of Akamai {OPEN} Auth for PHP

    635 Bytes - 2015-10-24T20:32:11-04:00 + 2015-10-29T21:00:58-04:00 diff --git a/docs/source/Handler/index.html b/docs/source/Handler/index.html index 4bbc9c9..04e3907 100644 --- a/docs/source/Handler/index.html +++ b/docs/source/Handler/index.html @@ -61,7 +61,7 @@

    Source of Akamai {OPEN} Auth for PHP

    3.5 KB - 2015-10-24T20:33:04-04:00 + 2015-10-29T21:00:58-04:00 @@ -69,7 +69,7 @@

    Source of Akamai {OPEN} Auth for PHP

    4.8 KB - 2015-10-24T20:32:11-04:00 + 2015-10-29T21:00:58-04:00 @@ -77,7 +77,7 @@

    Source of Akamai {OPEN} Auth for PHP

    6.1 KB - 2015-10-24T20:33:04-04:00 + 2015-10-29T21:00:58-04:00 diff --git a/docs/source/index.html b/docs/source/index.html index 3aea928..7f12479 100644 --- a/docs/source/index.html +++ b/docs/source/index.html @@ -69,15 +69,15 @@

    Source of Akamai {OPEN} Auth for PHP

    12.2 KB - 2015-10-24T20:32:11-04:00 + 2015-10-29T21:00:58-04:00 Cli.php - 5.8 KB + 9.7 KB - 2015-10-24T20:33:08-04:00 + 2015-10-29T23:46:38-04:00 @@ -85,7 +85,7 @@

    Source of Akamai {OPEN} Auth for PHP

    17.7 KB - 2015-10-24T20:48:20-04:00 + 2015-10-29T23:46:38-04:00 @@ -102,7 +102,7 @@

    Source of Akamai {OPEN} Auth for PHP

    583 Bytes - 2015-10-24T20:32:11-04:00 + 2015-10-29T21:00:58-04:00