diff --git a/README.md b/README.md index 8963ae3..8c26408 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Vendor Versions -Vendor Versions is a bar panel for [Tracy](https://tracy.nette.org/) debugger. It loads `composer.lock` file and shows you versions of all currently installed libraries. +Vendor Versions is a bar panel for [Tracy](https://tracy.nette.org/) debugger. It loads `composer.json` and `composer.lock` files and shows you versions of all currently installed libraries. + +![Tracy panel screenshot](https://github.com/milo/vendor-versions/raw/master/screenshot.png) # Installation @@ -10,7 +12,7 @@ If you are using Nette DI container, register panel in `config.neon`: extensions: vendorVersions: Milo\VendorVersions\Bridges\Nette\DI\Extension(%debugMode%) -# Optionally set path do directory with composer.lock file +# Optionally set path do directory with composer.json and composer.lock files vendorVersions: dir: 'some/path' ``` @@ -22,12 +24,8 @@ Tracy\Debugger::getBar()->addPanel( ); -# Optionally with a path to directory with composer.lock file +# Optionally with a path to directory with composer.json and composer.lock files Tracy\Debugger::getBar()->addPanel( new Milo\VendorVersions\Panel(__DIR__ . '/some/dir') ); ``` - - -# Screenshot -![Tracy panel screenshot](https://github.com/milo/vendor-versions/raw/master/screenshot.png) diff --git a/screenshot.png b/screenshot.png index 4908b9f..ed78a81 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/src/Panel.php b/src/Panel.php index d2f54eb..5f19be5 100644 --- a/src/Panel.php +++ b/src/Panel.php @@ -53,23 +53,17 @@ public function getPanel() { ob_start(); - if ($this->error === NULL) { - $file = $this->dir . DIRECTORY_SEPARATOR . 'composer.lock'; - $json = @file_get_contents($file); - if ($json === FALSE) { - $this->error = error_get_last()['message']; - return NULL; - } - - $decoded = @json_decode($json, TRUE); - if (!is_array($decoded)) { - $this->error = error_get_last()['message']; - return NULL; - } + $jsonFile = $this->dir . DIRECTORY_SEPARATOR . 'composer.json'; + $lockFile = $this->dir . DIRECTORY_SEPARATOR . 'composer.lock'; + + $required = $this->decode($jsonFile); + $installed = $this->decode($lockFile); + if ($this->error === NULL) { + $required += ['require' => [], 'require-dev' => []]; $data = [ - 'Packages' => self::format($decoded['packages']), - 'Dev Packages' => self::format($decoded['packages-dev']), + 'Packages' => self::format($installed['packages'], $required['require']), + 'Dev Packages' => self::format($installed['packages-dev'], $required['require-dev']), ]; } @@ -82,17 +76,23 @@ public function getPanel() /** * @param array $packages + * @param array $required * @return array */ - private static function format(array $packages) + private static function format(array $packages, array $required) { $data = []; foreach ($packages as $p) { $data[$p['name']] = (object) [ - 'version' => $p['version'] . ($p['version'] === 'dev-master' + 'installed' => $p['version'] . ($p['version'] === 'dev-master' ? (' #' . substr($p['source']['reference'], 0, 7)) : '' ), + + 'required' => isset($required[$p['name']]) + ? $required[$p['name']] + : NULL, + 'url' => isset($p['source']['url']) ? preg_replace('/\.git$/', '', $p['source']['url']) : NULL, @@ -103,4 +103,26 @@ private static function format(array $packages) return $data; } + + /** + * @param string $file + * @return array|NULL + */ + private function decode($file) + { + $json = @file_get_contents($file); + if ($json === FALSE) { + $this->error = error_get_last()['message']; + return NULL; + } + + $decoded = @json_decode($json, TRUE); + if (!is_array($decoded)) { + $this->error = error_get_last()['message']; + return NULL; + } + + return $decoded; + } + } diff --git a/src/templates/Panel.panel.phtml b/src/templates/Panel.panel.phtml index 951f0c1..9f6df41 100644 --- a/src/templates/Panel.panel.phtml +++ b/src/templates/Panel.panel.phtml @@ -9,7 +9,8 @@ function h($str) { } /** - * @var string|NULL $file + * @var string|NULL $lockFile + * @var string|NULL $jsonFile * @var string|NULL $error * @var array $data */ @@ -24,13 +25,18 @@ function h($str) { } .milo-VendorVersionsPanel .tracy-inner { - width: 350px; + width: 500px; } .milo-VendorVersionsPanel table { white-space: nowrap; font: 9pt/1.5 Consolas,monospace !important; } + + .milo-VendorVersionsPanel td.version { + /*color: green !important;*/ + font-weight: bold !important; + }
@@ -45,20 +51,22 @@ function h($str) { Name - Version + Installed + Required $p): ?> url ? ("" . h($name) . "") : h($name) ?> - version) ?> + installed) ?> + required) ?> -

Source:

+

Source: