示例#1
0
 /**
  * @group CoreFunctions
  * @covers FluentDOMCore::namespaces
  */
 public function testNamespacesWithChaining()
 {
     $fd = new FluentDOM();
     $fd->namespaces(array('test' => 'http://test.only/'));
     $fdChild = $fd->spawn();
     $this->assertAttributeEquals(array('test' => 'http://test.only/'), '_namespaces', $fdChild);
 }
示例#2
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;
 }