diff --git a/composer.json b/composer.json index edd25823d..971f5ac58 100644 --- a/composer.json +++ b/composer.json @@ -30,13 +30,18 @@ "require": { "php": ">=5.4", "ext-mbstring": "*", - "yiisoft/yii2": "~2.0.13" + "yiisoft/yii2": "~2.0.13", + "samdark/yii2-psr-log-target": "dev-master", + "yiisoft/yii-http": "dev-master" }, "require-dev": { "yiisoft/yii2-swiftmailer": "*", "yiisoft/yii2-coding-standards": "~2.0", "cweagans/composer-patches": "^1.7", - "phpunit/phpunit": "4.8.34" + "phpunit/phpunit": "4.8.34", + "yiisoft/yii-debug": "dev-master", + "yiisoft/router-fastroute": "^3.0", + "yiisoft/yii-debug-api": "dev-master" }, "autoload": { "psr-4": { @@ -73,7 +78,8 @@ "config": { "allow-plugins": { "cweagans/composer-patches": true, - "yiisoft/yii2-composer": true + "yiisoft/yii2-composer": true, + "yiisoft/config": false } } } diff --git a/src/LogTarget.php b/src/LogTarget.php index 5d94fdda3..850b29686 100644 --- a/src/LogTarget.php +++ b/src/LogTarget.php @@ -39,7 +39,7 @@ public function __construct($module, $config = []) { parent::__construct($config); $this->module = $module; - $this->tag = uniqid(); + //$this->tag = uniqid(); } /** @@ -53,7 +53,7 @@ public function export() FileHelper::createDirectory($path, $this->module->dirMode); $summary = $this->collectSummary(); - $dataFile = "$path/{$this->tag}.data"; + $dataFile = "$path/{$this->module->debugger->getId()}.data"; $data = []; $exceptions = []; foreach ($this->module->panels as $id => $panel) { @@ -115,7 +115,7 @@ public function loadTagToPanels($tag) $exceptions = $data['exceptions']; foreach ($this->module->panels as $id => $panel) { if (isset($data[$id])) { - $panel->tag = $tag; + $panel->tag = $this->module->debugger->getId(); $panel->load(unserialize($data[$id])); } else { unset($this->module->panels[$id]); @@ -152,7 +152,7 @@ private function updateIndexFile($indexFile, $summary) $manifest = unserialize($manifest); } - $manifest[$this->tag] = $summary; + $manifest[$this->module->debugger->getId()] = $summary; $this->gc($manifest); ftruncate($fp, 0); @@ -245,7 +245,7 @@ protected function collectSummary() $request = Yii::$app->getRequest(); $response = Yii::$app->getResponse(); $summary = [ - 'tag' => $this->tag, + 'tag' => $this->module->debugger->getId(), 'url' => $request instanceof yii\console\Request ? "php yii " . implode(' ', $request->getParams()): $request->getAbsoluteUrl(), 'ajax' => $request instanceof yii\console\Request ? 0 : (int) $request->getIsAjax(), 'method' => $request instanceof yii\console\Request ? 'COMMAND' : $request->getMethod(), diff --git a/src/Module.php b/src/Module.php index dd065b298..0e2ef7f7e 100644 --- a/src/Module.php +++ b/src/Module.php @@ -7,16 +7,42 @@ namespace yii\debug; +use HttpSoft\Message\ServerRequest; +use HttpSoft\Message\Stream; +use HttpSoft\Message\Uri; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Psr\Log\NullLogger; +use samdark\log\PsrTarget; +use stdClass; +use Symfony\Component\Console\Event\ConsoleEvent; use Yii; use yii\base\Application; use yii\base\BootstrapInterface; +use yii\base\Event; use yii\helpers\Html; use yii\helpers\IpHelper; use yii\helpers\Json; use yii\helpers\Url; +use yii\log\Target; use yii\web\ForbiddenHttpException; +use yii\web\Request; use yii\web\Response; use yii\web\View; +use Yiisoft\VarDumper\VarDumper; +use Yiisoft\Yii\Debug\Collector\Console\CommandCollector; +use Yiisoft\Yii\Debug\Collector\LogCollector; +use Yiisoft\Yii\Debug\Collector\LoggerInterfaceProxy; +use Yiisoft\Yii\Debug\Collector\TimelineCollector; +use Yiisoft\Yii\Debug\Collector\VarDumperCollector; +use Yiisoft\Yii\Debug\Collector\VarDumperHandlerInterfaceProxy; +use Yiisoft\Yii\Debug\Collector\Web\RequestCollector; +use Yiisoft\Yii\Debug\Collector\Web\WebAppInfoCollector; +use Yiisoft\Yii\Debug\Debugger; +use Yiisoft\Yii\Debug\Storage\FileStorage; +use Yiisoft\Yii\Debug\Storage\StorageInterface; +use Yiisoft\Yii\Http\Event\AfterRequest; +use Yiisoft\Yii\Http\Event\BeforeRequest; /** * The Yii Debug Module provides the debug toolbar and debugger @@ -50,7 +76,8 @@ class Module extends \yii\base\Module implements BootstrapInterface * * The signature is the following: * - * function (Action|null $action) The action can be null when called from a non action context (like set debug header) + * function (Action|null $action) The action can be null when called from a non action context (like set debug + * header) * * @since 2.1.0 */ @@ -63,12 +90,14 @@ class Module extends \yii\base\Module implements BootstrapInterface * @var LogTarget|array|string the logTarget object, or the configuration for creating the logTarget object. */ public $logTarget = 'yii\debug\LogTarget'; + /** * @var \yii\rbac\BaseManager|string|array the RBAC access checker [[BaseManager]] object or the application * component ID of the AuthManager [[BaseManager]]. * @since 2.1.19 */ public $authManager = 'authManager'; + /** * @var array|Panel[] list of debug panels. The array keys are the panel IDs, and values are the corresponding * panel class names or configuration arrays. This will be merged with [[corePanels()]]. @@ -134,8 +163,8 @@ class Module extends \yii\base\Module implements BootstrapInterface */ public $disableCallbackRestrictionWarning = false; /** - * @var mixed the string with placeholders to be be substituted or an anonymous function that returns the trace line string. - * The placeholders are {file}, {line} and {text} and the string should be as follows: + * @var mixed the string with placeholders to be be substituted or an anonymous function that returns the trace + * line string. The placeholders are {file}, {line} and {text} and the string should be as follows: * * `File: {file} - Line: {line} - Text: {text}` * @@ -205,6 +234,9 @@ class Module extends \yii\base\Module implements BootstrapInterface */ public $skipAjaxRequestUrl = []; + + public Debugger|null $debugger = null; + /** * Returns the logo URL to be used in `format( + $dataResponseFactory->createResponse([ + 'data' => $data, + ]) + )->getBody(); + } +} diff --git a/src/controllers/DefaultController.php b/src/controllers/DefaultController.php index 99e9559f6..a8d8c8c78 100644 --- a/src/controllers/DefaultController.php +++ b/src/controllers/DefaultController.php @@ -7,11 +7,21 @@ namespace yii\debug\controllers; +use HttpSoft\Message\ResponseFactory; +use HttpSoft\Message\StreamFactory; use Yii; use yii\debug\models\search\Debug; +use yii\debug\Module; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\web\Response; +use Yiisoft\DataResponse\DataResponse; +use Yiisoft\DataResponse\DataResponseFactory; +use Yiisoft\DataResponse\Formatter\JsonDataResponseFormatter; +use Yiisoft\DataResponse\Middleware\FormatDataResponseAsJson; +use Yiisoft\Yii\Debug\Api\Debug\Controller\DebugController; +use Yiisoft\Yii\Debug\Api\Debug\Repository\CollectorRepository; +use Yiisoft\Yii\Debug\Storage\FileStorage; /** * Debugger controller provides browsing over available debug logs. @@ -73,6 +83,23 @@ public function beforeAction($action) */ public function actionIndex() { + $dataResponseFactory = Yii::createObject(DataResponseFactory::class, [ + 'responseFactory' => Yii::createObject(ResponseFactory::class, []), + 'streamFactory' => Yii::createObject(StreamFactory::class, []) + ]); + $collectorRepository = Yii::createObject(CollectorRepository::class, [ + 'storage' => new FileStorage(Yii::getAlias('@runtime/debug')), + ]); + $controller = Yii::createObject(DebugController::class, [ + 'responseFactory' => $dataResponseFactory, + 'collectorRepository' => $collectorRepository + ]); + $result = $controller->index(); + return (new JsonDataResponseFormatter()) + ->format( + $dataResponseFactory->createResponse($result->getData()) + )->getBody(); + $searchModel = new Debug(); $dataProvider = $searchModel->search($_GET, $this->getManifest());