koel/app/Application.php

101 lines
2.5 KiB
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App;
2015-12-27 14:06:10 +00:00
use Cache;
use GuzzleHttp\Client;
2015-12-13 04:42:28 +00:00
use Illuminate\Foundation\Application as IlluminateApplication;
use InvalidArgumentException;
2015-12-27 14:06:10 +00:00
use Log;
2015-12-13 04:42:28 +00:00
/**
* Extends \Illuminate\Foundation\Application to override some defaults.
*/
class Application extends IlluminateApplication
{
2015-12-28 01:47:32 +00:00
/**
* Current Koel version. Must start with a v, and is synced with git tags/releases.
*
* @link https://github.com/phanan/koel/releases
*/
2016-03-06 08:28:47 +00:00
const VERSION = 'v2.2.0';
2015-12-27 14:06:10 +00:00
/**
* We have merged public path and base path.
*
* @return string
*/
public function publicPath()
{
return $this->basePath;
}
2015-12-13 04:42:28 +00:00
/**
* Loads a revision'ed asset file, making use of gulp-rev
* This is a copycat of L5's Elixir, but catered to our directory structure.
*
* @param string $file
* @param string $manifestFile
2015-12-13 04:42:28 +00:00
*
* @return string
*/
public function rev($file, $manifestFile = null)
2015-12-13 04:42:28 +00:00
{
static $manifest = null;
$manifestFile = $manifestFile ?: $this->publicPath().'/public/build/rev-manifest.json';
2015-12-13 04:42:28 +00:00
if (is_null($manifest)) {
$manifest = json_decode(file_get_contents($manifestFile), true);
2015-12-13 04:42:28 +00:00
}
if (isset($manifest[$file])) {
return $this->staticUrl("public/build/{$manifest[$file]}");
2015-12-13 04:42:28 +00:00
}
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
}
2015-12-27 14:06:10 +00:00
/**
2016-02-09 00:33:21 +00:00
* Get a URL for static file requests.
* If this installation of Koel has a CDN_URL configured, use it as the base.
* Otherwise, just use a relative '/'.
*
2016-02-03 15:39:15 +00:00
* @param string $name The additional resource name/path.
2016-02-09 00:33:21 +00:00
*
* @return string
*/
public function staticUrl($name = null)
{
return trim(env('CDN_URL'), '/ ').'/'.trim(ltrim($name, '/'));
}
2015-12-27 14:06:10 +00:00
/**
* Get the latest version number of Koel from Github.
2016-02-03 15:39:15 +00:00
*
* @param Client $client
*
2015-12-27 14:06:10 +00:00
* @return string
*/
public function getLatestVersion(Client $client = null)
{
$client = $client ?: new Client();
if ($v = Cache::get('latestKoelVersion')) {
return $v;
}
try {
$v = json_decode($client->get('https://api.github.com/repos/phanan/koel/tags')->getBody())[0]->name;
// Cache for a week
Cache::put('latestKoelVersion', $v, 7 * 24 * 60);
return $v;
} catch (\Exception $e) {
Log::error($e);
return self::VERSION;
}
}
2015-12-13 04:42:28 +00:00
}