Moosh\Command\Generic\Plugin\PluginList::execute PHP Метод

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

public execute ( )
    public function execute()
    {
        $filepath = $this->expandedOptions['path'];
        $stat = NULL;
        if (file_exists($filepath)) {
            $stat = stat($filepath);
        }
        if (!$stat || time() - $stat['mtime'] > 60 * 60 * 24 || !$stat['size']) {
            @unlink($filepath);
            file_put_contents($filepath, fopen(self::$APIURL, 'r'));
        }
        $jsonfile = file_get_contents($filepath);
        if ($jsonfile === false) {
            die("Can't read json file");
        }
        $data = json_decode($jsonfile);
        if (!$data) {
            unlink($filepath);
            cli_error("Invalid JSON file, deleted {$filepath}. Run command again.");
        }
        $fulllist = array();
        foreach ($data->plugins as $k => $plugin) {
            if (!$plugin->component) {
                continue;
            }
            $fulllist[$plugin->component] = array('releases' => array());
            foreach ($plugin->versions as $v => $version) {
                if ($this->expandedOptions['versions']) {
                    $fulllist[$plugin->component]['releases'][$version->version] = $version;
                } else {
                    foreach ($version->supportedmoodles as $supportedmoodle) {
                        $fulllist[$plugin->component]['releases'][$supportedmoodle->release] = $version;
                    }
                }
                $fulllist[$plugin->component]['url'] = $version->downloadurl;
            }
        }
        ksort($fulllist);
        foreach ($fulllist as $k => $plugin) {
            $versions = array_keys($plugin['releases']);
            sort($versions);
            echo "{$k}," . implode(",", $versions) . "," . $plugin['url'] . "\n";
        }
    }