diff --git a/README.md b/README.md index c27fa8c..8963ae3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,33 @@ -# vendor-versions -Tracy panel with installed libraries version +# 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. + + +# Installation +Use [Composer](https://getcomposer.org) and require `milo/vendor-versions` package. + +If you are using Nette DI container, register panel in `config.neon`: +```yaml +extensions: + vendorVersions: Milo\VendorVersions\Bridges\Nette\DI\Extension(%debugMode%) + +# Optionally set path do directory with composer.lock file +vendorVersions: + dir: 'some/path' +``` + +If you are not using Nette DI, register panel manually: +```php +Tracy\Debugger::getBar()->addPanel( + new Milo\VendorVersions\Panel +); + + +# Optionally with a path to directory with composer.lock file +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/composer.json b/composer.json new file mode 100644 index 0000000..6053b07 --- /dev/null +++ b/composer.json @@ -0,0 +1,26 @@ +{ + "name": "milo/vendor-versions", + "type": "library", + "description": "Bar with versions list of vendor libraries for Tracy", + "keywords": ["tracy", "bar", "vendor", "composer", "composer.lock"], + "license": ["MIT"], + "authors": [ + { + "name": "Miloslav Hůla", + "email": "miloslav.hula@gmail.com", + "homepage": "https://github.com/milo" + } + ], + "require": { + "php": ">=5.4.0", + "tracy/tracy": "^2.3.0" + }, + "suggest": { + "nette/di": "For automatic panel loading" + }, + "autoload": { + "psr-4": { + "Milo\\VendorVersions\\": "src/" + } + } +} diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..4908b9f Binary files /dev/null and b/screenshot.png differ diff --git a/src/Bridges/Nette/DI/Extension.php b/src/Bridges/Nette/DI/Extension.php new file mode 100644 index 0000000..6f331aa --- /dev/null +++ b/src/Bridges/Nette/DI/Extension.php @@ -0,0 +1,45 @@ + NULL, + ]; + + /** @var bool */ + private $debugMode; + + + /** + * @param bool $debugMode + */ + public function __construct($debugMode) + { + $this->debugMode = $debugMode; + } + + + public function loadConfiguration() + { + if ($this->debugMode) { + $config = $this->getConfig() + $this->defaults; + + $container = $this->getContainerBuilder(); + $container->getDefinition('tracy.bar') + ->addSetup('addPanel', [ + new Nette\DI\Statement('Milo\VendorVersions\Panel', [$config['dir']]) + ]); + } + } + +} diff --git a/src/Panel.php b/src/Panel.php new file mode 100644 index 0000000..d2f54eb --- /dev/null +++ b/src/Panel.php @@ -0,0 +1,106 @@ +error = "Path '$composerLockDir' is not a directory."; + } elseif (!is_file($dir . DIRECTORY_SEPARATOR . 'composer.lock')) { + $this->error = "Directory '$dir' does not contain the composer.lock file."; + } else { + $this->dir = $dir; + } + } + + + /** + * @return string + */ + public function getTab() + { + ob_start(); + require __DIR__ . '/templates/Panel.tab.phtml'; + return ob_get_clean(); + } + + + /** + * @return string + */ + 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; + } + + $data = [ + 'Packages' => self::format($decoded['packages']), + 'Dev Packages' => self::format($decoded['packages-dev']), + ]; + } + + $error = $this->error; + + require __DIR__ . '/templates/Panel.panel.phtml'; + return ob_get_clean(); + } + + + /** + * @param array $packages + * @return array + */ + private static function format(array $packages) + { + $data = []; + foreach ($packages as $p) { + $data[$p['name']] = (object) [ + 'version' => $p['version'] . ($p['version'] === 'dev-master' + ? (' #' . substr($p['source']['reference'], 0, 7)) + : '' + ), + 'url' => isset($p['source']['url']) + ? preg_replace('/\.git$/', '', $p['source']['url']) + : NULL, + ]; + } + + ksort($data); + return $data; + } + +} diff --git a/src/templates/Panel.panel.phtml b/src/templates/Panel.panel.phtml new file mode 100644 index 0000000..951f0c1 --- /dev/null +++ b/src/templates/Panel.panel.phtml @@ -0,0 +1,64 @@ + + + +
+

Vendor Versions

+
+ + + + $packages): ?> +

+ + + + + + + + + $p): ?> + + + + + + +
NameVersion
url ? ("" . h($name) . "") : h($name) ?>version) ?>
+ +

Source:

+ +
+
diff --git a/src/templates/Panel.tab.phtml b/src/templates/Panel.tab.phtml new file mode 100644 index 0000000..f7f6e2f --- /dev/null +++ b/src/templates/Panel.tab.phtml @@ -0,0 +1,3 @@ + + +