PHP code example of wisonlau / hyperf-debug

1. Go to this page and download the library: Download wisonlau/hyperf-debug library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wisonlau / hyperf-debug example snippets


'servers' => [
    [
        'name' => 'ws',
        'type' => Server::SERVER_WEBSOCKET,
        'host' => '0.0.0.0',
        'port' => 9502,
        'sock_type' => SWOOLE_SOCK_TCP,
        'callbacks' => [
            Event::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],
            Event::ON_MESSAGE => [Hyperf\WebSocketServer\Server::class, 'onMessage'],
            Event::ON_CLOSE => [Hyperf\WebSocketServer\Server::class, 'onClose'],
        ],
    ],
],

Router::addRoute(['GET', 'POST', 'HEAD'], '/hpdebug', function() {
    $wsdebug = new \Wisonlau\HyperfDebug\Hpdebug();
    $response = new \Hyperf\HttpServer\Response();
    return $response->raw($wsdebug->getHtml())->withHeader('content-type', 'text/html; charset=utf-8');
});

Router::addServer('ws', function () {
    Router::get('/', Wisonlau\HyperfDebug\Hpdebug::class);
});

php>=8.0

namespace App\HttpController;

use Hyperf\Di\Annotation\Inject;
use Wisonlau\HyperfDebug\Hpdebug;

class TestController 
{
    #[Inject]
	protected Hpdebug $debug;

	public function test()
	{
		$userData = [
		    'uid' => 1,
		    'username' => 'hyperf-debug',
		];
		$this->debug->send($userData);
	}
}

php<8.0

namespace App\HttpController;

use Hyperf\Di\Annotation\Inject;
use Wisonlau\HyperfDebug\Hpdebug;

class TestController 
{
   /**
    * @Inject()
    * @var Hpdebug
    */
	protected $debug;

	public function test()
	{
		$userData = [
		    'uid' => 1,
		    'username' => 'hyperf-debug',
		];
		$this->debug->send($userData);
	}
}