Gc\Version::getLatest PHP Метод

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

Fetches the version of the latest stable release.
public static getLatest ( ) : string
Результат string
    public static function getLatest()
    {
        if (null === self::$latestVersion) {
            self::$latestVersion = 'not available';
            $url = 'https://api.github.com/repos/GotCms/GotCms/git/refs/tags';
            try {
                $client = new Client($url, array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'timeout' => 2, 'ssltransport' => STREAM_CRYPTO_METHOD_TLS_CLIENT, 'sslverifypeer' => false));
                $response = $client->send();
                if ($response->isSuccess()) {
                    $content = $response->getBody();
                }
            } catch (\Exception $e) {
                //Don't care
            }
            //Try to retrieve with file_get_contents
            if (empty($content)) {
                $content = @file_get_contents($url);
            }
            if (!empty($content)) {
                $apiResponse = Json::decode($content, Json::TYPE_ARRAY);
                // Simplify the API response into a simple array of version numbers
                $tags = array_map(function ($tag) {
                    return substr($tag['ref'], 10);
                    // Reliable because we're filtering on 'refs/tags/'
                }, $apiResponse);
                // Fetch the latest version number from the array
                self::$latestVersion = array_reduce($tags, function ($a, $b) {
                    return version_compare($a, $b, '>') ? $a : $b;
                });
            }
        }
        return self::$latestVersion;
    }

Usage Example

Пример #1
0
 /**
  * Display dashboard
  *
  * @return array
  */
 public function indexAction()
 {
     $data = array();
     $data['version'] = Version::VERSION;
     $data['versionIsLatest'] = Version::isLatest();
     $data['versionLatest'] = Version::getLatest();
     $documents = new Collection();
     $contentStats = array();
     $contentStats['online_documents'] = array('count' => count($documents->getAvailableDocuments()), 'label' => 'Online documents', 'route' => 'content');
     $contentStats['total_documents'] = array('count' => count($documents->select()->toArray()), 'label' => 'Total documents', 'route' => 'content');
     $data['contentStats'] = $contentStats;
     $visitorModel = new Visitor();
     $data['userStats'] = array('total_visitors' => array('count' => $visitorModel->getTotalVisitors(), 'label' => 'Total visitors', 'route' => 'statistics'), 'total_visits' => array('count' => $visitorModel->getTotalPageViews(), 'label' => 'Total page views', 'route' => 'statistics'));
     $coreConfig = $this->getServiceLocator()->get('CoreConfig');
     $widgets = @unserialize($coreConfig->getValue('dashboard_widgets'));
     $data['dashboardSortable'] = !empty($widgets['sortable']) ? Json::encode($widgets['sortable']) : '{}';
     $data['dashboardWelcome'] = !empty($widgets['welcome']);
     $data['customeWidgets'] = array();
     $this->events()->trigger(__CLASS__, 'dashboard', $this, array('widgets' => &$data['customeWidgets']));
     return $data;
 }
All Usage Examples Of Gc\Version::getLatest