Exemplo n.º 1
0
function process($directory, $category)
{
    $files = glob($directory . '/*.xml');
    foreach ($files as $file) {
        $contents = file_get_contents($file);
        if (strpos($contents, '<example>') !== false) {
            continue;
        }
        $examplePosition = strpos($contents, '</refentry>');
        if ($examplePosition === false) {
            echo "{$file} couldn't find </refentry> \n";
            continue;
        }
        $basename = basename($file, '.xml');
        $exampleInfo = CategoryNav::findExample($category, $basename);
        if ($exampleInfo == null) {
            //echo "No example at all for $category::$basename\n";
            continue;
        }
        list($exampleCategory, $exampleFunction) = $exampleInfo;
        $docHelper = new DocHelperDisplay($exampleCategory, $exampleFunction);
        $xml = $docHelper->getXML();
        $start = substr($contents, 0, $examplePosition);
        $end = substr($contents, $examplePosition);
        $newContents = $start;
        $newContents .= $xml;
        $newContents .= $end;
        $written = @file_put_contents($file, $newContents);
        if ($written == false) {
            echo "Failed to write contents to file {$file} \n";
            exit(0);
        }
        echo "Added example to {$file} \n";
        //exit(0);
    }
}
Exemplo n.º 2
0
 if (is_array($function) == true) {
     if (is_array($function[0])) {
         $function = $function[0][0];
     } else {
         $function = $function[0];
     }
 }
 $parts = explode('\\', $function);
 if (count($parts) == 3) {
     $category = $parts[1];
     $name = $parts[2];
 } else {
     echo "failed to parse " . var_export($function, true);
     exit(-1);
 }
 $docHelper = new DocHelperDisplay($category, $name);
 $examples = $docHelper->getExamples();
 $count = 0;
 foreach ($examples as $example) {
     $count += 1;
     $codeExample = unserialize($example);
     /** @var $codeExample \ImagickDemo\CodeExample */
     if (count($examples) == 1) {
         $caseName = 'basic';
     } else {
         $caseName = $codeExample->getDescription();
         $caseName = trim($caseName);
         if (strlen($caseName) == 0) {
             $caseName = "case{$count}";
         }
     }