/**
  * Get a plugin's component name.
  *
  * @return string
  *
  * @throws \RuntimeException
  */
 public function getComponent()
 {
     // Simple cache.
     if (!empty($this->component)) {
         return $this->component;
     }
     $filter = new StatementFilter();
     $parser = new CodeParser();
     $notFound = 'The plugin must define the $plugin->component in the version.php file.';
     $statements = $parser->parseFile($this->directory . '/version.php');
     try {
         $assign = $filter->findFirstPropertyFetchAssignment($statements, 'plugin', 'component', $notFound);
     } catch (\Exception $e) {
         $assign = $filter->findFirstPropertyFetchAssignment($statements, 'module', 'component', $notFound);
     }
     if (!$assign->expr instanceof String_) {
         throw new \RuntimeException('The $plugin->component must be assigned to a string in the version.php file.');
     }
     $this->component = $assign->expr->value;
     return $this->component;
 }
Example #2
0
 /**
  * Get the branch number, EG: 29, 30, etc.
  *
  * @return int
  */
 public function getBranch()
 {
     $filter = new StatementFilter();
     $parser = new CodeParser();
     $statements = $parser->parseFile($this->directory . '/version.php');
     $assign = $filter->findFirstVariableAssignment($statements, 'branch', 'Failed to find $branch in Moodle version.php');
     if ($assign->expr instanceof String_) {
         return (int) $assign->expr->value;
     }
     throw new \RuntimeException('Failed to find Moodle branch version');
 }
 /**
  * Get a plugin's dependencies.
  *
  * @return array
  */
 public function getDependencies()
 {
     // Simple cache.
     if (is_array($this->dependencies)) {
         return $this->dependencies;
     }
     $this->dependencies = [];
     $filter = new StatementFilter();
     $parser = new CodeParser();
     $statements = $parser->parseFile($this->directory . '/version.php');
     try {
         $assign = $filter->findFirstPropertyFetchAssignment($statements, 'plugin', 'dependencies');
     } catch (\Exception $e) {
         try {
             $assign = $filter->findFirstPropertyFetchAssignment($statements, 'module', 'dependencies');
         } catch (\Exception $e) {
             return $this->dependencies;
         }
     }
     if (!$assign->expr instanceof Array_) {
         throw new \RuntimeException('The $plugin->dependencies must be assigned to an array in the version.php file.');
     }
     $this->dependencies = $filter->arrayStringKeys($assign->expr);
     return $this->dependencies;
 }