Habari\Update::check PHP Метод

check() публичный статический Метод

Notifies update_check plugin hooks when checking so that they can add their beaconids to the list.
public static check ( ) : array
Результат array An array of update beacon information for components that have updates
    public static function check()
    {
        try {
            // get a local version of the instance to save typing
            $instance = self::instance();
            // load beacons
            self::register_beacons();
            // setup the remote request
            $request = new RemoteRequest(self::UPDATE_URL, 'POST');
            // add all the beacon versions as parameters
            $request->set_params(Utils::array_map_field($instance->beacons, 'version'));
            // we're not desperate enough to wait too long
            $request->set_timeout(5);
            // execute the request
            $result = $request->execute();
            // grab the body of the response, which has our xml in it
            $update_data = $request->get_response_body();
            // i don't know why we hold the XML in a class variable, but we'll keep doing that in this rewrite
            $instance->update = new \SimpleXMLElement($update_data);
            foreach ($instance->update as $beacon) {
                $beacon_id = (string) $beacon['id'];
                $beacon_url = (string) $beacon['url'];
                $beacon_type = isset($beacon['type']) ? (string) $beacon['type'] : 'addon';
                // do we have this beacon? if not, don't process it
                // even though we POST all our beacons to the update script right now, it still hands back the whole list
                if (empty($instance->beacons[$beacon_id])) {
                    continue;
                }
                // add the beacon's basic info
                $instance->beacons[$beacon_id]['id'] = $beacon_id;
                $instance->beacons[$beacon_id]['url'] = $beacon_url;
                $instance->beacons[$beacon_id]['type'] = $beacon_type;
                foreach ($beacon->update as $update) {
                    // pick out and cast all the values from the XML
                    $u = array('severity' => (string) $update['severity'], 'version' => (string) $update['version'], 'date' => isset($update['date']) ? (string) $update['date'] : '', 'url' => isset($update['url']) ? (string) $update['url'] : '', 'text' => (string) $update);
                    // if the remote update info version is newer... we want all newer versions
                    if (version_compare($u['version'], $instance->beacons[$beacon_id]['version']) > 0) {
                        // if this version is more recent than all the other versions
                        if (!isset($instance->beacons[$beacon_id]['latest_version']) || version_compare($u['version'], $instance->beacons[$beacon_id]['latest_version']) > 0) {
                            // set this as the latest version
                            $instance->beacons[$beacon_id]['latest_version'] = $u['version'];
                        }
                        // add the version to the list
                        $instance->beacons[$beacon_id]['updates'][$u['version']] = $u;
                    }
                }
            }
            // return an array of beacons that have updates
            return array_filter($instance->beacons, Method::create('\\Habari\\Update', 'filter_unchanged'));
        } catch (\Exception $e) {
            // catches any RemoteRequest errors or XML parsing problems, etc.
            // bubble up
            throw $e;
        }
    }