Commit ee2c8d64 by 孙龙

init

parents
{
"name": "ListenMysql/Listen",
"description": "监听sql",
"type": "library",
"authors": [
{
"name": "sunlong",
"email": "long@ichunt.com"
}
],
"require": {
"laravel/framework": "^5.1"
},"autoload": {
"psr-4": {
"ListenMysql\\Listen\\":"src/"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
<?php
namespace ListenMysql\Listen;
use DB;
use Log;
use Event;
use App;
class AddEveryMysql{
public $config = [];
public $allList = [];
public function __construct($config=[])
{
$this->config = $config;
}
public function listen(){
try{
if(!isset($this->config['enabled']) || !$this->config['enabled']) return false;
$querys = [
'urls'=>['host'=>app('request')->server('HTTP_HOST'),'path'=>app('request')->path(),'method'=>app('request')->method()],
'datas'=>[],
];
$host = app('request')->server('HTTP_HOST');
$path = app('request')->path();
$method = app('request')->method();
$arr = new static;
@DB::listen(function($query)use($querys,$arr){
$tmp = str_replace('?', '"'.'%s'.'"', $query->sql);
$tmp = vsprintf($tmp, $query->bindings);
$tmp = str_replace("\\","",$tmp);
\Log::info("host {$querys['urls']['host']} url:{$querys['urls']['path']} method:".$querys['urls']['method']." [queryTime:{$query->time}ms]".$tmp."\n\n\t");
// $arr->add("123");
});
}catch(\Exception $e){
}
}
public function add($str){
$this->allList[] = $str;
}
}
\ No newline at end of file
<?php
namespace ListenMysql\Listen;
use Illuminate\Support\ServiceProvider;
class ListenMysqlServiceProvider extends ServiceProvider {
/**
* Boot the provider.
*
* @return void
*/
public function boot()
{
$this->publishes([
__DIR__.'/config.php' => config_path('listenMysql.php'),
]);
}
/**
* 在容器中注册绑定.
*
* @return void
*/
public function register()
{
$this->app->singleton(AddEveryMysql::class, function ($app) {
$config = config('listenMysql');
return new AddEveryMysql($config);
});
app(AddEveryMysql::class)->listen();
}
}
\ No newline at end of file
<?php
namespace ListenMysql\Listen;
use Illuminate\Support\Facades\Facade;
class ListenMsql extends Facade{
public static function getFacadeAccessor()
{
return 'listenmsql';
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment