Exakat\Tasks\FindExternalLibraries::run PHP Метод

run() публичный Метод

public run ( )
    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');
        }
    }

Usage Example

Пример #1
0
 public function execute(Config $config)
 {
     switch ($config->command) {
         case 'doctor':
             $doctor = new Tasks\Doctor($this->gremlin, $this->config);
             $doctor->run($config);
             break;
         case 'init':
             $task = new Tasks\Initproject($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'anonymize':
             $task = new Tasks\Anonymize($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'files':
             $task = new Tasks\Files($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'load':
             $task = new Tasks\Load($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'stat':
             $task = new Tasks\Stat($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'analyze':
             $task = new Tasks\Analyze($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'results':
             $task = new Tasks\Results($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'export':
             $task = new Tasks\Export($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'report':
             $task = new Tasks\Report2($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'project':
             $task = new Tasks\Project($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'magicnumber':
             $task = new Tasks\Magicnumber($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'clean':
             $task = new Tasks\Clean($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'status':
             $task = new Tasks\Status($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'help':
             $task = new Tasks\Help($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'cleandb':
             $task = new Tasks\CleanDb($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'onepage':
             $task = new Tasks\OnePage($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'update':
             $task = new Tasks\Update($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'onepagereport':
             $task = new Tasks\OnepageReport($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'phploc':
             $task = new Tasks\Phploc($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'findextlib':
             $task = new Tasks\FindExternalLibraries($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'dump':
             $task = new Tasks\Dump($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'jobqueue':
             $task = new Tasks\Jobqueue($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'queue':
             $task = new Tasks\Queue($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'test':
             $task = new Tasks\Test($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'remove':
             $task = new Tasks\Remove($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'server':
             $task = new Tasks\Server($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'upgrade':
             $task = new Tasks\Upgrade($this->gremlin, $this->config);
             $task->run($config);
             break;
         case 'version':
         default:
             $version = self::VERSION;
             $build = self::BUILD;
             $date = date('r', filemtime(__FILE__));
             echo "\n ________                 __              _    \n|_   __  |               [  |  _         / |_  \n  | |_ \\_| _   __  ,--.   | | / ]  ,--. `| |-' \n  |  _| _ [ \\ [  ]`'_\\ :  | '' <  `'_\\ : | |   \n _| |__/ | > '  < // | |, | |`\\ \\ // | |,| |,  \n|________|[__]`\\_]\\'-;__/[__|  \\_]\\'-;__/\\__/  \n                                               \n\nExakat : @ 2014-2016 Damien Seguy. \nVersion : ", $version, ' - Build ', $build, ' - ', $date, "\n";
             break;
     }
 }
All Usage Examples Of Exakat\Tasks\FindExternalLibraries::run
FindExternalLibraries