/**
  * @param string $url
  * @return string
  */
 public function tokenizeSingleUrl($url)
 {
     if (!preg_match($this->aclRegex, $url, $matches)) {
         return $url;
     }
     $acl = $matches[0] . $this->aclPostfix;
     $c = new Akamai_EdgeAuth_Config();
     $c->set_acl($acl);
     $c->set_window($this->window);
     $c->set_start_time(time());
     # The time from which the token will start
     $c->set_key($this->salt);
     $g = new Akamai_EdgeAuth_Generate();
     $token = $g->generate_token($c);
     if (strpos($url, '?') === false) {
         $url .= '?';
     } else {
         $url .= '&';
     }
     return $url . "{$this->param}={$token}";
 }
 // bring in getopt and define some exit codes
 require_once 'Console/Getopt.php';
 define('NO_ARGS', 10);
 define('INVALID_OPTION', 11);
 // parse args to opts
 $args = Console_Getopt::readPHPArgv();
 $long_opts = array('help', 'window=', 'start-time=', 'ip=', 'acl=', 'session-id=', 'payload=', 'url=', 'salt=', 'field-delimiter=', 'acl-delimiter=', 'algo=', 'key=', 'debug', 'escape-early');
 $opts = Console_Getopt::getOpt($args, 'h', $long_opts);
 // Check the options are valid
 if (PEAR::isError($opts)) {
     fwrite(STDERR, $opts->getMessage() . "\n");
     exit(INVALID_OPTION);
 }
 if (!empty($opts[0])) {
     $c = new Akamai_EdgeAuth_Config();
     $g = new Akamai_EdgeAuth_Generate();
     foreach ($opts[0] as $o) {
         if ($o[0] == '--help') {
             //@TODO
             print "php akamai_token_v2.php [options]\n";
             print "ie.\n";
             print "php akamai_token_v2.php --start=now --window=86400\n";
             print "\n";
             print "--ip=IP_ADDRESS     IP Address to restrict this token to.\n";
             print "--start-time=       What is the start time. (Use now for the current time)\n";
             print "--window=WINDOW_SECONDS\n";
             print "                    How long is this token valid for?\n";
             print "--url=URL           URL path. [Used for:URL]\n";
             print "--acl=ACCESS_LIST   Access control list delimited by ! [ie. /*]\n";
             print "--key=KEY           Secret required to generate the token.\n";
             print "--payload=PAYLOAD   Additional text added to the calculated digest.\n";
 /**
  * @param string $acl
  * @return string
  */
 protected function generateToken($acl)
 {
     $c = new Akamai_EdgeAuth_Config();
     $c->set_acl($acl);
     $c->set_window($this->window);
     $c->set_start_time(time());
     # The time from which the token will start
     $c->set_key($this->key);
     $g = new Akamai_EdgeAuth_Generate();
     return $g->generate_token($c);
 }