echo "Cannot find collection in {$filepath}\n";
        return;
    }
    $className = $m[1];
    if ($className[0] === '\\') {
        $className = substr($className, 1);
    } else {
        if (preg_match('#use (\\S*\\\\' . $className . ');#', $file, $m)) {
            $className = $m[1];
        } else {
            preg_match('#namespace (s9e[^;]+)#', $file, $m);
            $className = $m[1] . '\\' . $className;
        }
    }
    $methods = getMethodAnnotations($className);
    $old = $file;
    $file = preg_replace_callback("#(?<=\n)(?:(/[*]+\n(?:[*](?! @method).*\n)*?)(?:[*]\n)*(?:[*] @method.*\n)*[*]/\n)?class#", function ($m) use($methods) {
        $doc = isset($m[1]) ? $m[1] : "\n/**\n";
        foreach ($methods as $text) {
            $doc .= '* @method ' . $text . "\n";
        }
        $doc .= "*/\nclass";
        return $doc;
    }, $file);
    if ($file !== $old) {
        echo "Patched {$filepath}\n";
        file_put_contents($filepath, $file);
    }
}
patchDir(__DIR__ . '/../src');
//getMethodAnnotations('s9e\\TextFormatter\\Configurator\\Collections\\RulesGeneratorList');
Exemple #2
0
    array_map('patchFile', glob($dirpath . '/*.md'));
}
function patchFile($filepath)
{
    $file = file_get_contents($filepath);
    // Execute PHP and replace output
    $text = preg_replace_callback('#
			(?<block>```php(?<code>[^`]++)```)
			\\s*
			(?<open>```\\w*|<pre>(?:<code>)?)
			(?<output>[^`]*)
			(?<close>```|</code></pre>)(?=\\n|$)
		#sx', function ($m) {
        $php = preg_replace('/\\$configurator =.*/', "\$0\n\$configurator->registeredVars['cacheDir'] = " . var_export(__DIR__ . '/../tests/.cache', true) . ";\n", $m['code']);
        ob_start();
        eval($php);
        $output = rtrim(ob_get_clean(), "\n");
        return $m['block'] . "\n" . $m['open'] . "\n" . $output . "\n" . $m['close'];
    }, $file);
    if ($text !== $file) {
        echo "Patching {$filepath}\n";
        file_put_contents($filepath, $text);
    }
}
patchDir(__DIR__ . '/../docs/Bundles');
patchDir(__DIR__ . '/../docs/Filters');
patchDir(__DIR__ . '/../docs/Getting_started');
patchDir(__DIR__ . '/../docs/Plugins');
patchDir(__DIR__ . '/../docs/Rules');
patchDir(__DIR__ . '/../docs/Templating');
die("Done.\n");
{
    $dirpath = realpath($dirpath);
    array_map('patchDir', glob($dirpath . '/*', GLOB_ONLYDIR));
    array_map('patchFile', glob($dirpath . '/*.md'));
}
function patchFile($filepath)
{
    $file = file_get_contents($filepath);
    // Execute the lone PHP in 02_Expert.md
    if (strpos($filepath, '02_Expert.md')) {
        $text = preg_replace_callback('#```php([^`]+)\\n```\\s+(?!```html|<pre>)#s', function ($m) {
            eval($m[1]);
            return $m[0];
        }, $file);
    }
    // Execute PHP and replace output
    $text = preg_replace_callback('#(```php([^`]+)\\n```\\s+(?:```\\w*|<pre>)).*?(\\n(?:```|</pre>)(?:\\n|$))#s', function ($m) {
        $php = preg_replace('/\\$configurator =.*/', "\$0\n\$configurator->registeredVars['cacheDir'] = " . var_export(__DIR__ . '/../tests/.cache', true) . ";\n", $m[2]);
        ob_start();
        eval($php);
        return $m[1] . "\n" . rtrim(ob_get_clean(), "\n") . $m[3];
    }, $file);
    if ($text !== $file) {
        echo "Patching {$filepath}\n";
        file_put_contents($filepath, $text);
    }
}
patchDir(__DIR__ . '/../src/Plugins/');
patchDir(__DIR__ . '/../docs/Cookbook/');
patchFile(__DIR__ . '/../docs/StorageFormat.md');
die("Done.\n");