├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── config.php ├── docs ├── _index.md ├── installation.md └── usage.md ├── helpers.php └── src ├── DumpServerCommand.php ├── DumpServerServiceProvider.php ├── Dumper.php └── RequestContextProvider.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-dump-server` will be documented in this file 4 | 5 | ## Unreleased 6 | 7 | - laravel 9 support 8 | 9 | ## 1.0.0 - 2018-07-09 10 | 11 | - initial release 12 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Beyond Code GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Dump Server 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/beyondcode/laravel-dump-server.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-dump-server) 4 | [![Total Downloads](https://img.shields.io/packagist/dt/beyondcode/laravel-dump-server.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-dump-server) 5 | 6 | Bringing the [Symfony Var-Dump Server](https://symfony.com/doc/current/components/var_dumper.html#the-dump-server) to Laravel. 7 | 8 | This package will give you a dump server, that collects all your `dump` call outputs, so that it does not interfere with HTTP / API responses. 9 | 10 | ## Installation 11 | 12 | You can install the package via composer: 13 | 14 | ```bash 15 | composer require --dev beyondcode/laravel-dump-server 16 | ``` 17 | 18 | ## Documentation 19 | 20 | You can find the documentation on the [Beyond Code website](https://beyondco.de/docs/laravel-dump-server/installation). 21 | 22 | ## Looking for `dump` on steroids? Check out Laravel Herd! 23 | Herd logo 24 | 25 | 26 | Herd Pro gives you a powerful interface to help you watch and collect your debug information. 27 | 28 | All of your application's `dump()` and `dd()` calls will be beautifully formatted and can be filtered from Herd's separate Dump window. 29 | 30 | Just keep using `dump()` as usual – Herd will take care of the rest. 31 | 32 | [herd.laravel.com](https://herd.laravel.com) 33 | 34 | ## Contributing 35 | 36 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 37 | 38 | ### Security 39 | 40 | If you discover any security related issues, please email marcel@beyondco.de instead of using the issue tracker. 41 | 42 | ## Credits 43 | 44 | - [Marcel Pociot](https://github.com/mpociot) 45 | - [All Contributors](../../contributors) 46 | 47 | ## License 48 | 49 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 50 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "beyondcode/laravel-dump-server", 3 | "description": "Symfony Var-Dump Server for Laravel", 4 | "keywords": [ 5 | "beyondcode", 6 | "laravel-dump-server" 7 | ], 8 | "homepage": "https://github.com/beyondcode/laravel-dump-server", 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Marcel Pociot", 13 | "email": "marcel@beyondco.de", 14 | "homepage": "https://beyondco.de", 15 | "role": "Developer" 16 | } 17 | ], 18 | "conflict": { 19 | "spatie/laravel-ray": "*" 20 | }, 21 | "require": { 22 | "php": ">=7.2.5", 23 | "illuminate/console": "5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", 24 | "illuminate/http": "5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", 25 | "illuminate/support": "5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", 26 | "symfony/var-dumper": "^5.0|^6.0|^7.0" 27 | }, 28 | "require-dev": { 29 | "larapack/dd": "^1.0", 30 | "phpunit/phpunit": "^7.0|^9.3|^10.5" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "BeyondCode\\DumpServer\\": "src" 35 | }, 36 | "files": [ 37 | "helpers.php" 38 | ] 39 | }, 40 | "autoload-dev": { 41 | "psr-4": { 42 | "BeyondCode\\DumpServer\\Tests\\": "tests" 43 | } 44 | }, 45 | "scripts": { 46 | "test": "vendor/bin/phpunit", 47 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 48 | }, 49 | "config": { 50 | "sort-packages": true 51 | }, 52 | "extra": { 53 | "laravel": { 54 | "providers": [ 55 | "BeyondCode\\DumpServer\\DumpServerServiceProvider" 56 | ] 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | env('DUMP_SERVER_HOST', 'tcp://127.0.0.1:9912'), 8 | ]; 9 | -------------------------------------------------------------------------------- /docs/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | packageName: Laravel Dump Server 3 | githubUrl: https://github.com/beyondcode/laravel-dump-server 4 | --- -------------------------------------------------------------------------------- /docs/installation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Installation 3 | order: 1 4 | --- 5 | # Laravel Dump Server 6 | 7 | Bringing the Symfony Var-Dump Server to Laravel. 8 | 9 | This package will give you a dump server, that collects all your dump call outputs, so that it does not interfere with HTTP / API responses. 10 | 11 | ![Dump Server Demo](/img/example.gif) 12 | 13 | # Installation 14 | 15 | You can install the package via composer: 16 | 17 | ```bash 18 | composer require --dev beyondcode/laravel-dump-server 19 | ``` 20 | 21 | The package will register itself automatically. 22 | 23 | Optionally you can publish the package configuration using: 24 | 25 | ```bash 26 | php artisan vendor:publish --provider="BeyondCode\DumpServer\DumpServerServiceProvider" 27 | ``` 28 | 29 | This will publish a file called `debug-server.php` in your `config` folder. 30 | In the config file, you can specify the dump server host that you want to listen on, in case you want to change the default value. 31 | -------------------------------------------------------------------------------- /docs/usage.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Usage 3 | order: 2 4 | --- 5 | 6 | # Usage 7 | 8 | Start the dump server by calling the artisan command: 9 | 10 | ```bash 11 | php artisan dump-server 12 | ``` 13 | 14 | You can set the output format to HTML using the `--format` option: 15 | 16 | ```bash 17 | php artisan dump-server --format=html > dump.html 18 | ``` 19 | 20 | Now you can put regular `dump` statements in your code. Instead of dumping the output directly in the HTTP response, the dumped data will be shown inside of your terminal / the running artisan command. 21 | 22 | This is very useful, when you want to dump data from API requests, without having to deal with HTTP errors. -------------------------------------------------------------------------------- /helpers.php: -------------------------------------------------------------------------------- 1 | basePath('config').($path ? DIRECTORY_SEPARATOR.$path : $path); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/DumpServerCommand.php: -------------------------------------------------------------------------------- 1 | server = $server; 47 | 48 | parent::__construct(); 49 | } 50 | 51 | /** 52 | * Handle the command. 53 | * 54 | * @return void 55 | */ 56 | public function handle() 57 | { 58 | switch ($format = $this->option('format')) { 59 | case 'cli': 60 | $descriptor = new CliDescriptor(new CliDumper); 61 | break; 62 | case 'html': 63 | $descriptor = new HtmlDescriptor(new HtmlDumper); 64 | break; 65 | default: 66 | throw new InvalidArgumentException(sprintf('Unsupported format "%s".', $format)); 67 | } 68 | 69 | $io = new SymfonyStyle($this->input, $this->output); 70 | 71 | $errorIo = $io->getErrorStyle(); 72 | $errorIo->title('Laravel Var Dump Server'); 73 | 74 | $this->server->start(); 75 | 76 | $errorIo->success(sprintf('Server listening on %s', $this->server->getHost())); 77 | $errorIo->comment('Quit the server with CONTROL-C.'); 78 | 79 | $this->server->listen(function (Data $data, array $context, int $clientId) use ($descriptor, $io) { 80 | $descriptor->describe($io, $data, $context, $clientId); 81 | }); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/DumpServerServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 21 | 22 | $this->publishes([ 23 | __DIR__.'/../config/config.php' => config_path('debug-server.php'), 24 | ], 'config'); 25 | } 26 | } 27 | 28 | /** 29 | * Register the application services. 30 | * 31 | * @return void 32 | */ 33 | public function register() 34 | { 35 | $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'debug-server'); 36 | 37 | $this->app->bind('command.dumpserver', DumpServerCommand::class); 38 | 39 | $this->commands([ 40 | 'command.dumpserver', 41 | ]); 42 | 43 | $host = $this->app['config']->get('debug-server.host'); 44 | 45 | $this->app->when(DumpServer::class)->needs('$host')->give($host); 46 | 47 | $connection = new Connection($host, [ 48 | 'request' => new RequestContextProvider($this->app['request']), 49 | 'source' => new SourceContextProvider('utf-8', base_path()), 50 | ]); 51 | 52 | VarDumper::setHandler(function ($var) use ($connection) { 53 | $this->app->makeWith(Dumper::class, ['connection' => $connection])->dump($var); 54 | }); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Dumper.php: -------------------------------------------------------------------------------- 1 | connection = $connection; 28 | } 29 | 30 | /** 31 | * Dump a value with elegance. 32 | * 33 | * @param mixed $value 34 | * @return void 35 | */ 36 | public function dump($value) 37 | { 38 | if (class_exists(CliDumper::class)) { 39 | $data = $this->createVarCloner()->cloneVar($value); 40 | 41 | if ($this->connection === null || $this->connection->write($data) === false) { 42 | $dumper = in_array(PHP_SAPI, ['cli', 'phpdbg']) ? new CliDumper : new HtmlDumper; 43 | $dumper->dump($data); 44 | } 45 | } else { 46 | var_dump($value); 47 | } 48 | } 49 | 50 | /** 51 | * @return VarCloner 52 | */ 53 | protected function createVarCloner(): VarCloner 54 | { 55 | return new VarCloner(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/RequestContextProvider.php: -------------------------------------------------------------------------------- 1 | currentRequest = $currentRequest; 34 | $this->cloner = new VarCloner; 35 | $this->cloner->setMaxItems(0); 36 | } 37 | 38 | /** 39 | * Get the context. 40 | * 41 | * @return array|null 42 | */ 43 | public function getContext(): ?array 44 | { 45 | if ($this->currentRequest === null) { 46 | return null; 47 | } 48 | 49 | $controller = null; 50 | 51 | if ($route = $this->currentRequest->route()) { 52 | $controller = $route->controller; 53 | 54 | if (! $controller && ! is_string($route->action['uses'])) { 55 | $controller = $route->action['uses']; 56 | } 57 | } 58 | 59 | return [ 60 | 'uri' => $this->currentRequest->getUri(), 61 | 'method' => $this->currentRequest->getMethod(), 62 | 'controller' => $controller ? $this->cloner->cloneVar(class_basename($controller)) : $this->cloner->cloneVar(null), 63 | 'identifier' => spl_object_hash($this->currentRequest), 64 | ]; 65 | } 66 | } 67 | --------------------------------------------------------------------------------