Skip to content

Commit

Permalink
Refactored Voyager
Browse files Browse the repository at this point in the history
  • Loading branch information
marktopper committed Dec 21, 2016
1 parent e1c44c9 commit cb6ad90
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
vendor
build
.lock
composer.lock
91 changes: 41 additions & 50 deletions src/Voyager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,37 @@

namespace TCG\Voyager;

use TCG\Voyager\Models\User;
use TCG\Voyager\Models\Setting;
use TCG\Voyager\Models\Permission;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\File;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use TCG\Voyager\Models\Permission;
use TCG\Voyager\Models\Setting;
use TCG\Voyager\Models\User;

class Voyager
{
/**
* Singleton Voyager Class.
*/
private static $instance;

public static function getInstance()
{
if (null === static::$instance) {
static::$instance = new static();
}
protected $version;
protected $filesystem;

return static::$instance;
}

public function getVersion()
public function __construct()
{
$composer_lock = __DIR__.'/../../../../composer.lock';
$version = null;
$this->filesystem = app(Filesystem::class);

if (File::exists($composer_lock)) {
// Get the composer.lock file
$file = json_decode(
File::get($composer_lock)
);

// Loop through all the packages and get the version of voyager
foreach ($file->packages as $package) {
if ($package->name == 'tcg/voyager') {
$version = $package->version;
break;
}
}
}

return $version;
$this->findVersion();
}

protected function __construct()
{
}

private function __clone()
public static function getInstance()
{
}
if (null === static::$instance) {
static::$instance = new static();
}

private function __wakeup()
{
return static::$instance;
}

/**
* End Singleton operators.
*
* @param $key
* @param null $default
*
* @return null
*/
public static function setting($key, $default = null)
{
$setting = Setting::where('key', '=', $key)->first();
Expand Down Expand Up @@ -105,4 +69,31 @@ public static function can($permission)
}
}
}

public function getVersion()
{
return $this->version;
}

protected function findVersion()
{
if (!is_null($this->version)) {
return;
}

if ($this->filesystem->exists(base_path('composer.lock'))) {
// Get the composer.lock file
$file = json_decode(
$this->filesystem->get(base_path('composer.lock'))
);

// Loop through all the packages and get the version of voyager
foreach ($file->packages as $package) {
if ($package->name == 'tcg/voyager') {
$this->version = $package->version;
break;
}
}
}
}
}

0 comments on commit cb6ad90

Please sign in to comment.