Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Example version.php file
- $text = '
- This is a version.php file with its contents, friends
- and other variables. Let\'s see how we do parse it
- defined(\'MOODLE_INTERNAL\') || die();
- $plugin->version = 2010073100;
- $plugin->requires = 2010090501; // Requires this Moodle version
- $plugin->dependencies = array(
- \'mod_quiz\' => 2011090100,
- \'qtype_pmatch\' => ANY_VERSION);
- ';
- // Very basic implementation ;-) Tons of checks/cleanup needed (empties, bad formed, injected...)
- preg_match('/\$plugin\->dependencies\s*=\s*array\s*\((.*)\)/s', $text, $matches);
- if (isset($matches[1])) {
- $ofinterest = preg_replace('/[ \t\']+/s', '', trim($matches[1])); // Whitespace, comma cleanup
- $ofinterest = preg_replace('/[\n\r]+/s', '\n', $ofinterest); // CRLF cleanup
- $ofinterestarr = explode('\n', $ofinterest);
- foreach ($ofinterestarr as $dependency) {
- if (strpos($dependency, '=>') !== false) {
- $dependencyarr = explode('=>', $dependency);
- $dependencies[$dependencyarr[0]] = $dependencyarr[1];
- } else {
- die('wrong dependency spec');
- }
- }
- var_dump($dependencies);
- } else {
- die('not dependencies found');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement