public function __construct($gremlin, $config, $subtask = Tasks::IS_NOT_SUBTASK) { parent::__construct($gremlin, $config, $subtask); $this->php = new Phpexec(); if (!$this->php->isValid()) { throw new InvalidPHPBinary($this->php->getVersion()); } self::$PROP_OPTIONS = array('alternative' => self::$PROP_ALTERNATIVE, 'reference' => self::$PROP_REFERENCE, 'heredoc' => self::$PROP_HEREDOC, 'delimiter' => self::$PROP_DELIMITER, 'noDelimiter' => self::$PROP_NODELIMITER, 'variadic' => self::$PROP_VARIADIC, 'count' => self::$PROP_COUNT, 'fullnspath' => self::$PROP_FNSNAME, 'absolute' => self::$PROP_ABSOLUTE, 'alias' => self::$PROP_ALIAS, 'origin' => self::$PROP_ORIGIN, 'encoding' => self::$PROP_ENCODING, 'intval' => self::$PROP_INTVAL, 'strval' => self::$PROP_STRVAL, 'enclosing' => self::$PROP_ENCLOSING, 'args_max' => self::$PROP_ARGS_MAX, 'args_min' => self::$PROP_ARGS_MIN, 'bracket' => self::$PROP_BRACKET, 'close_tag' => self::$PROP_CLOSETAG); $this->php->getTokens(); Precedence::preloadConstants($this->php->getActualVersion()); $this->precedence = new Precedence(); }
public function run() { $project = $this->config->project; if ($project == 'default') { throw new ProjectNeeded(); } if (!file_exists($this->config->projects_root . '/projects/' . $project . '/')) { throw new NoSuchProject(); } $dir = $this->config->projects_root . '/projects/' . $project . '/code'; $configFile = $this->config->projects_root . '/projects/' . $project . '/config.ini'; $ini = parse_ini_file($configFile); if ($this->config->update && isset($ini['FindExternalLibraries'])) { display('Not updating ' . $project . '/config.ini. This tool was already run. Please, clean the config.ini file in the project directory, before running it again.'); return; //Cancel task } display('Processing files'); $files = $this->datastore->getCol('files', 'file'); if (empty($files)) { display('No files to process. Aborting'); return; } $this->php = new Phpexec(); $this->php->getTokens(); Precedence::preloadConstants($this->php->getActualVersion()); $r = array(); $path = $this->config->projects_root . '/projects/' . $project . '/code'; rsort($files); $ignore = 'None'; $ignoreLength = 0; foreach ($files as $id => $file) { if (substr($file, 0, $ignoreLength) == $ignore) { print "Ignore {$file} ({$ignore})\n"; continue; } $s = $this->process($path . $file); if (!empty($s)) { $r[] = $s; $ignore = array_pop($s); $ignoreLength = strlen($ignore); } } if (!empty($r)) { $newConfigs = call_user_func_array('array_merge', $r); } else { $newConfigs = array(); } if (count(array_keys($newConfigs)) == 1) { display('One external library is going to be omitted : ' . implode(', ', array_keys($newConfigs))); } elseif (!empty($newConfigs)) { display(count(array_keys($newConfigs)) . ' external libraries are going to be omitted : ' . implode(', ', array_keys($newConfigs))); } $store = array(); foreach ($newConfigs as $library => $file) { $store[] = array('library' => $library, 'file' => $file); } $this->datastore->cleanTable('externallibraries'); $this->datastore->addRow('externallibraries', $store); if ($this->config->update === true && !empty($newConfigs)) { display('Updating ' . $project . '/config.ini'); $ini = file_get_contents($configFile); $ini = preg_replace("#(ignore_dirs\\[\\] = \\/.*?\n)\n#is", '$1' . "\n" . ';Ignoring external libraries' . "\n" . 'ignore_dirs[] = ' . implode("\n" . 'ignore_dirs[] = ', $newConfigs) . "\n;Ignoring external libraries\n\n", $ini); $ini .= "\nFindExternalLibraries = 1\n"; file_put_contents($configFile, $ini); } else { display('Not updating ' . $project . '/config.ini. ' . count($newConfigs) . ' external libraries found'); } }