diff --git a/README.md b/README.md index a79c7db..b6dd667 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ $ ./vendor/bin/dependency-visualizer -h Usage: dependency-visualizer [options] Options: + -d: Load Xdebug. -h: Show this help. -l: Output log to current directory. -m: Draw methods in diagram. diff --git a/bin/dependency-visualizer b/bin/dependency-visualizer index 5e301e6..d4a524a 100755 --- a/bin/dependency-visualizer +++ b/bin/dependency-visualizer @@ -3,6 +3,7 @@ namespace Hirokinoue\DependencyVisualizer; +use Composer\XdebugHandler\XdebugHandler; use Hirokinoue\DependencyVisualizer\Config\Config; use Hirokinoue\DependencyVisualizer\Exporter\Exporter; use Hirokinoue\DependencyVisualizer\Exporter\PlantUmlExporter; @@ -21,6 +22,7 @@ list($options, $file) = parseArgs($argv); if ($options['help']) { echo 'Usage: dependency-visualizer [options] ' . PHP_EOL; echo 'Options:' . PHP_EOL; + echo ' -d: Load Xdebug.' . PHP_EOL; echo ' -h: Show this help.' . PHP_EOL; echo ' -l: Output log to current directory.' . PHP_EOL; echo ' -m: Draw methods in diagram.' . PHP_EOL; @@ -28,6 +30,11 @@ if ($options['help']) { exit(0); } +if ($options['loadXdebug'] === false) { + $xdebug = new XdebugHandler('dependency-visualizer'); + $xdebug->check(); + unset($xdebug); +} Config::initialize(\getcwd()); ini_set('memory_limit', Config::memoryLimit()); @@ -36,6 +43,7 @@ Logger::initialize($options['log']); Logger::info('autoload file has been loaded', ['path' => $loadedFile ?? '']); Logger::info('start analyzing', ['target' => $file]); +Logger::info('Xdebug is ' . (extension_loaded('xdebug') ? 'enabled.' : 'disabled.')); try { $dependencyVisualizer = DependencyVisualizer::create($file); @@ -63,6 +71,7 @@ function exporterFactory($options): Exporter { function parseArgs($args): array { $options = [ + 'loadXdebug' => false, 'help' => false, 'log' => false, 'drawMethod' => false, @@ -71,6 +80,9 @@ function parseArgs($args): array { $file = ''; foreach ($args as $arg) { switch ($arg) { + case '-d': + $options['loadXdebug'] = true; + break; case '-h': $options['help'] = true; break; diff --git a/composer.json b/composer.json index fade6fa..a5f8f0a 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "require": { "php": "^7.4|^8.0", "nikic/php-parser": "^5.0", - "monolog/monolog": "^2.5" + "monolog/monolog": "^2.5", + "composer/xdebug-handler": "^3.0" }, "require-dev": { "phpunit/phpunit": "^8.5", diff --git a/composer.lock b/composer.lock index 37149d0..0489f9d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,145 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "61979d561d98dfaaae51620c29cbae9a", + "content-hash": "dd5a9407ff4d6af4c3eed3f3f5270cf8", "packages": [ + { + "name": "composer/pcre", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/composer/pcre.git", + "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/pcre/zipball/00104306927c7a0919b4ced2aaa6782c1e61a3c9", + "reference": "00104306927c7a0919b4ced2aaa6782c1e61a3c9", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.3", + "phpstan/phpstan-strict-rules": "^1.1", + "symfony/phpunit-bridge": "^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Pcre\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "PCRE wrapping library that offers type-safe preg_* replacements.", + "keywords": [ + "PCRE", + "preg", + "regex", + "regular expression" + ], + "support": { + "issues": "https://github.com/composer/pcre/issues", + "source": "https://github.com/composer/pcre/tree/3.1.1" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2023-10-11T07:11:09+00:00" + }, + { + "name": "composer/xdebug-handler", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/composer/xdebug-handler.git", + "reference": "ced299686f41dce890debac69273b47ffe98a40c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ced299686f41dce890debac69273b47ffe98a40c", + "reference": "ced299686f41dce890debac69273b47ffe98a40c", + "shasum": "" + }, + "require": { + "composer/pcre": "^1 || ^2 || ^3", + "php": "^7.2.5 || ^8.0", + "psr/log": "^1 || ^2 || ^3" + }, + "require-dev": { + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-strict-rules": "^1.1", + "symfony/phpunit-bridge": "^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Composer\\XdebugHandler\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "John Stevenson", + "email": "john-stevenson@blueyonder.co.uk" + } + ], + "description": "Restarts a process without Xdebug.", + "keywords": [ + "Xdebug", + "performance" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/xdebug-handler/issues", + "source": "https://github.com/composer/xdebug-handler/tree/3.0.3" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2022-02-25T21:32:43+00:00" + }, { "name": "monolog/monolog", "version": "2.9.2",