Example #1
0
<?php

require __DIR__ . '/../vendor/autoload.php';
try {
    // Instantiate the HTTP client
    $client = new Artax\Client();
    // Let's build up a custom Request object
    $request = (new Artax\Request())->setMethod('POST')->setUri('http://httpbin.org/post')->setBody('zanzibar!');
    // Make an asynchronous HTTP request
    $promise = $client->request($request);
    // Client::request() is asynchronous! It doesn't return a response. Instead, it
    // returns a promise to resolve the response at some point in the future when
    // it's finished. Here we tell the promise that we want to wait for it to complete.
    $response = $promise->wait();
    // Output the results
    printf("\nHTTP/%s %d %s\n\n------- RESPONSE BODY -------\n%s\n", $response->getProtocol(), $response->getStatus(), $response->getReason(), $response->getBody());
} catch (Artax\ClientException $e) {
    // If something goes wrong the Promise::wait() call will throw the relevant
    // exception. The Client::request() method itself will never throw.
    echo $e;
}
Example #2
0
<?php

require __DIR__ . '/../vendor/autoload.php';
try {
    // Instantiate the HTTP client
    $client = new Artax\Client();
    // Make an asynchronous HTTP request
    $promise = $client->request('http://httpbin.org/user-agent');
    // Client::request() is asynchronous! It doesn't return a response. Instead, it
    // returns a promise to resolve the response at some point in the future when
    // it's finished. Here we tell the promise that we want to wait for it to complete.
    $response = $promise->wait();
    // Output the results
    printf("\nHTTP/%s %d %s\n", $response->getProtocol(), $response->getStatus(), $response->getReason());
} catch (Artax\ClientException $error) {
    // If something goes wrong the Promise::wait() call will throw the relevant
    // exception. The Client::request() method itself will never throw.
    echo $error;
}
Example #3
0
 function getDoc($fullURL, $classname, $method)
 {
     $client = new \Artax\Client();
     $request = new \Artax\Request();
     $client->setOption('transfertimeout', 25);
     echo "{$fullURL} \n";
     $request->setUri($fullURL);
     $request->setHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8');
     $request->setHeader('Accept-Encoding', 'gzip,deflate,sdch');
     $request->setHeader('Accept-Language', 'en-US,en;q=0.8');
     $request->setHeader('Host', 'svn.php.net');
     $request->setHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36');
     //Cache-Control:max-age=0
     //Connection:keep-alive
     //Cookie:MYPHPNET=%2C%2CNONE%2C0%2C; uvts=1nfuEIFstwB6CP0; LAST_NEWS=1401284942; COUNTRY=GBR%2C89.242.230.142; LAST_LANG=en
     //If-Modified-Since:Thu, 12 Jan 2012 05:08:38 GMT
     //If-None-Match:"322115//phpdoc/en/trunk/reference/imagick/imagick/annotateimage.xml"
     ///User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36
     $response = $client->request($request);
     if ($response->getStatus() != 200) {
         echo "Failed to read URL";
         echo $response->getBody();
         return null;
     }
     $contentTypeHeaders = $response->getHeader('Content-Type');
     if (array_key_exists(0, $contentTypeHeaders) == false) {
         throw new Exception("Content-type header not set.");
     }
     $contentType = $contentTypeHeaders[0];
     $colonPosition = strpos($contentType, ';');
     if ($colonPosition !== false) {
         $contentType = substr($contentType, 0, $colonPosition);
     }
     //    if ($contentType !== 'text/html') {
     //        echo "Unknown content type $contentType";
     //        return;
     //    }
     $SR = ['&reftitle.errors' => 'errors', '&example.outputs.similar' => 'similar', '&reftitle.returnvalues' => 'returnvalues', '&reftitle.examples' => 'examples', '&reftitle.seealso' => 'examples', '&reftitle.description' => 'description', '&reftitle.parameters' => 'parameters', '&reftitle.changelog' => 'changelog', '&Version' => 'Version', '&Description' => 'Description', '&true' => 'True', '&false' => 'False', '&return.success' => 'Return success', '&return.void' => 'return void', '&example.outputs' => 'Output', '&float' => 'float', '&reftitle.notes' => 'Notes', '&warn.undocumented.func' => 'Undocumented', '&no.function.parameters' => 'no.function.parameters', '&url.imagemagick.usage.transform.function' => 'transform.function', '&url.imagemagick' => 'ImageMagick URL'];
     $body = $response->getBody();
     $body = str_replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $GLOBALS['entityBlock'], $body);
     $body = str_replace(array_keys($SR), array_values($SR), $body);
     $fluentDOM = new FluentDOM();
     $fluentDOM->namespaces(['ref' => 'http://docbook.org/ns/docbook']);
     $manualEntry = new ManualEntry($classname, $method);
     //echo $body;
     $dom = $fluentDOM->load($body, 'text/xml');
     $methodParam = function (DOMElement $element) use($manualEntry) {
         $name = null;
         $type = null;
         foreach ($element->childNodes as $childNode) {
             if ($childNode instanceof DOMElement) {
                 if ($childNode->nodeName === 'type') {
                     $type = $childNode->textContent;
                 }
                 if ($childNode->nodeName === 'parameter') {
                     $name = $childNode->textContent;
                 }
             }
         }
         $manualEntry->addParam(new Parameter($type, $name));
     };
     $dom->find('//ref:methodparam')->each($methodParam);
     $description = function (DOMElement $element) use($manualEntry) {
         $manualEntry->setDescription($element->textContent);
     };
     $dom->find('//ref:refsect1[@role="description"]/ref:para')->each($description);
     $paramDescriptionBlock = $dom->find('//ref:refsect1[@role="parameters"]/ref:para/ref:variablelist/ref:varlistentry');
     foreach ($paramDescriptionBlock as $element) {
         /** @var DOMElement $element */
         //echo "Found entry \n";
         $paramName = null;
         $paramDescription = null;
         $subDOM = new FluentDOM();
         $subDOM->load($element);
         $subDOM->namespaces(['ref' => 'http://docbook.org/ns/docbook']);
         $termBlock = $subDOM->find("child::ref:term/ref:parameter");
         foreach ($termBlock as $term) {
             /** @var DOMElement $term */
             //echo $term->textContent."\n";
             $paramName .= trim($term->textContent);
         }
         $descriptionBlock = $subDOM->find("child::ref:listitem/ref:para");
         foreach ($descriptionBlock as $description) {
             /** @var DOMElement $term */
             $paramDescription .= trim($description->textContent);
         }
         $manualEntry->addParamDescription($paramName, $paramDescription);
     }
     $nameBlock = $dom->find('//ref:refnamediv/ref:refname');
     if ($nameBlock->count()) {
         foreach ($nameBlock as $nameElement) {
             /** @var DOMElement $term */
             $manualEntry->setFunctionName($nameElement->textContent);
         }
     }
     if ($nameBlock->count()) {
         $methodDescriptionBlock = $dom->find('//ref:refnamediv/ref:refpurpose');
         foreach ($methodDescriptionBlock as $methodDescriptionElement) {
             /** @var DOMElement $term */
             $manualEntry->setMethodDescription($methodDescriptionElement->textContent);
         }
     }
     $returnTypeBlock = $dom->find('//ref:refsect1[@role="returnvalues"]/ref:para');
     foreach ($returnTypeBlock as $returnTypeElement) {
         /** @var DOMElement $term */
         $manualEntry->setReturnType($returnTypeElement->textContent);
     }
     $this->manualEntries[] = $manualEntry;
     return $manualEntry;
 }
Example #4
0
<?php

require __DIR__ . '/../vendor/autoload.php';
try {
    // Instantiate the HTTP client
    $client = new Artax\Client();
    // Enable verbose sends so we can see our raw request messages in the console
    // as they're sent to the server.
    $client->setOption(Artax\Client::OP_VERBOSITY, Artax\Client::VERBOSE_SEND);
    // This request will receive and store google's Set-Cookie headers.
    $response = $client->request('http://www.google.com/')->wait();
    // And this request will send the cookie we received in the first request.
    // In your console you'll see that this second request contains a Cookie header.
    $response = $client->request('http://www.google.com/')->wait();
} catch (Artax\ClientException $e) {
    // If something goes wrong the Promise::wait() call will throw the relevant
    // exception. The Client::request() method itself will never throw.
    echo $e;
}