lahaxearnaud / clockwork
PHP 开发 Chrome 扩展 Clockwork 的服务器端组件
Requires
- php: >=5.3.9
- psr/log: 1.*
README
Clockwork 是一个用于 PHP 开发的 Chrome 扩展,通过扩展开发者工具的新面板,提供各种信息,用于调试和性能分析你的 PHP 应用程序,包括请求、头部、GET 和 POST 数据、Cookies、会话数据、数据库查询、路由、应用程序运行时可视化等。
你不是 Chrome 用户?请查看 Clockwork 的可嵌入 Web 应用程序版本,支持许多现代浏览器,包括 Chrome,并自带对 Laravel 和 Slim 的支持。还有可用的第三方 Firebug 扩展 和 CLI 客户端应用程序。
此存储库包含 Clockwork 的服务器端组件,该组件收集所有数据,以 JSON 格式存储,并在 Chrome 开发者工具扩展中显示。
安装
此扩展为 Laravel、Slim 2 和 CodeIgniter 2.1 框架提供开箱即用的支持,您可以通过可扩展的 API 添加对其他或自定义框架的支持。
要安装最新版本,只需将其添加到您的 composer.json
"itsgoingd/clockwork": "~1.9"
Laravel
安装 Clockwork 后,您需要在 app/config/app.php
中注册 Laravel 服务提供者。
'providers' => array( ... 'Clockwork\Support\Laravel\ClockworkServiceProvider' )
当使用 Laravel 5 时,您需要在 app/Http/Kernel.php
中添加 Clockwork 中间件。
protected $middleware = [ 'Clockwork\Support\Laravel\ClockworkMiddleware', ... ]
默认情况下,Clockwork 只在调试模式下可用,您可以在配置文件中更改此设置和其他设置。使用以下 Artisan 命令将配置文件发布到您的配置目录
$ php artisan vendor:publish --provider='Clockwork\Support\Laravel\ClockworkServiceProvider'
对于 Laravel 4,您可以使用此命令完成相同的操作
$ php artisan config:publish itsgoingd/clockwork --path vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/config/
Clockwork 还附带了一个外观,它提供了一种轻松将记录添加到 Clockwork 日志和事件添加到时间线的简单方法。您可以在 app/config/app.php
中注册外观。
'aliases' => array( ... 'Clockwork' => 'Clockwork\Support\Laravel\Facade', )
现在您可以使用以下命令
Clockwork::startEvent('event_name', 'Event description.'); // event called 'Event description.' appears in Clockwork timeline tab Clockwork::info('Message text.'); // 'Message text.' appears in Clockwork log tab Log::info('Message text.'); // 'Message text.' appears in Clockwork log tab as well as application log file Clockwork::info(array('hello' => 'world')); // logs json representation of the array Clockwork::info(new Object()); // logs string representation of the objects if the object implements __toString magic method, logs json representation of output of toArray method if the object implements it, if neither is the case, logs json representation of the object cast to array Clockwork::endEvent('event_name');
Lumen
安装 Clockwork 后,您需要在 bootstrap/app.php
中注册 Clockwork 服务提供者。
$app->register(Clockwork\Support\Lumen\ClockworkServiceProvider::class);
您还需要在同一个文件中添加 Clockwork 中间件。
$app->middleware([ ... Clockwork\Support\Lumen\ClockworkMiddleware::class ]);
默认情况下,Clockwork 只在调试模式下可用(APP_DEBUG
设置为 true),您可以通过环境变量更改此设置和其他设置。只需指定以 CLOCKWORK_
为前缀的设置作为环境变量,例如 CLOCKWORK_ENABLE
,可用设置的完整列表。
Clockwork 还附带了一个外观,它提供了一种轻松将记录添加到 Clockwork 日志和事件添加到时间线的简单方法。当您在 bootstrap/app.php
中启用外观时,外观将自动注册。
$app->withFacades();
现在您可以使用以下命令
Clockwork::startEvent('event_name', 'Event description.'); // event called 'Event description.' appears in Clockwork timeline tab Clockwork::info('Message text.'); // 'Message text.' appears in Clockwork log tab Log::info('Message text.'); // 'Message text.' appears in Clockwork log tab as well as application log file Clockwork::info(array('hello' => 'world')); // logs json representation of the array Clockwork::info(new Object()); // logs string representation of the objects if the object implements __toString magic method, logs json representation of output of toArray method if the object implements it, if neither is the case, logs json representation of the object cast to array Clockwork::endEvent('event_name');
Slim 2
安装 Clockwork 后,您需要将 Slim 中间件添加到您的应用程序中。
$app = new Slim(...); $app->add(new Clockwork\Support\Slim\ClockworkMiddleware('/requests/storage/path'));
Clockwork 现在可在 Slim 的 DI 容器中使用,如下所示
$app = Slim::getInstance(); $app->clockwork->startEvent('event_name', 'Event description.'); // event called 'Event description.' appears in Clockwork timeline tab $app->clockwork->info('Message text.'); // 'Message text.' appears in Clockwork log tab $app->log->info('Message text.'); // 'Message text.' appears in Clockwork log tab as well as application log file $app->clockwork->endEvent('event_name');
CodeIgniter 2.1
安装 Clockwork 后,您需要将 Clockwork 控制器从 vendor/itsgoingd/clockwork/Clockwork/Support/CodeIgniter/Clockwork.php
复制到您的控制器目录,并设置以下路由
$route['__clockwork/(.*)'] = 'clockwork/$1';
最后,您需要通过在您的 application/config/hooks.php
文件中添加以下内容来设置 Clockwork 钩子
Clockwork\Support\CodeIgniter\Register::registerHooks($hook);
要在控制器/模型等中使用 Clockwork,您需要扩展您的 CI_Controller
类。(如果您还没有这样做的话)在 application/core/MY_Controller.php
创建一个新的文件。
class MY_Controller extends CI_Controller { public function __construct() { parent::__construct(); $GLOBALS['EXT']->_call_hook('pre_controller_constructor'); } }
现在您可以在您的 CodeIgniter 应用程序中使用以下命令
$this->clockwork->startEvent('event_name', 'Event description.'); // event called 'Event description.' appears in Clockwork timeline tab $this->clockwork->info('Message text.'); // 'Message text.' appears in Clockwork log tab $this->clockwork->endEvent('event_name');
其他框架
有一个简要的架构概述可用,这应该在实施对新框架或自定义应用程序的支持时提供一些帮助。
如果您想查看或正在开发对尚不支持框架的支持,请随时在 GitHub 上创建一个新的问题。
附加组件
- clockwork-cli - 由 ptrofimov 提供的 Clockwork 命令行界面
- guzzle-clockwork - 由 hannesvdvreken 提供的用于记录 Guzzle 请求到 Clockwork 的插件
- silverstripe-clockwork - 由 markguinn 提供的 SilverStripe CMS/框架集成
- clockwork-firebug - 由 Pavel Sidorovich 提供的 Firebug 扩展(类似于 Chrome 中的 Firebug)
许可证
版权所有(c)2013 Miroslav Rigler
MIT 许可证
特此授予任何获得本软件及其相关文档文件(以下简称“软件”)副本的个人免费使用软件的权利,不受限制地处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许向软件提供方提供软件的人士这样做,前提是遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
本软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任负责,无论此类责任是基于合同、侵权或其他方式,是否因软件或其使用或其他方式引起、产生或与之相关。