Skip to content

Commit

Permalink
Merge pull request #30 from eeliu/feat-php8.1
Browse files Browse the repository at this point in the history
ProfilerMysqli_Stmt in php8.1
  • Loading branch information
EyelynSu authored Jan 12, 2022
2 parents 289b089 + 5c7e46d commit ada408e
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/Pinpoint/Plugins/Sys/mysqli/Mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class Mysqli extends \mysqli
{
public function prepare ($query)
public function prepare (string $query):\mysqli_stmt|false
{
$plugin = new MysqliPreparePlugin("Mysqli::prepare",$this,$query);
try{
Expand All @@ -33,7 +33,7 @@ public function prepare ($query)
}
}

public function query ($query, $resultmode = MYSQLI_STORE_RESULT)
public function query (string $query, int $resultmode = MYSQLI_STORE_RESULT):\mysqli_result|bool
{
$plugin = new MysqliQueryPlugin("Mysqli::query",$this,$query, $resultmode);
try{
Expand Down
103 changes: 84 additions & 19 deletions lib/Pinpoint/Plugins/Sys/mysqli/ProfilerMysqli_Stmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,31 @@
* User: eeliu
* Date: 11/5/20
* Time: 5:32 PM
* changes: 2022-1-11: php8.1, the only way is extends all function
*/

namespace Pinpoint\Plugins\Sys\mysqli;


class ProfilerMysqli_Stmt
class ProfilerMysqli_Stmt extends \mysqli_stmt
{
protected $_instance;
public function __construct(&$instance)
{
$this->_instance = &$instance;
}

public function __call($name, $arguments)
public function bind_result (mixed &...$vars): bool
{
return call_user_func_array([&$this->_instance,$name],$arguments);
return $this->_instance->bind_result(...$vars);
}

public function bind_param ($types, &$var1, &...$_)
{
$param = \pinpoint_get_func_ref_args();
return call_user_func_array([$this->_instance,'bind_param'],$param);

}

public function bind_result (&$var1, &...$_)
{
$param = \pinpoint_get_func_ref_args();
return call_user_func_array([$this->_instance,'bind_result'],$param);
}

public function execute()
public function execute(?array $params = null): bool
{
$plugin = new StmtExecutePlugin("Stmt::execute",$this);
try{
$plugin->onBefore();
$ret = call_user_func_array([$this->_instance,'execute'],[]);
$ret = call_user_func([$this->_instance,'execute'],$params);
$plugin->onEnd($ret);
return $ret;

Expand All @@ -49,5 +37,82 @@ public function execute()
}
}

public function attr_get(int $attribute): int
{
return call_user_func([$this->_instance,'attr_get'],$attribute);
}

public function attr_set(int $attribute, int $value): bool
{
return call_user_func([$this->_instance,'attr_set'],$attribute,$value);
}

public function bind_param(string $types, mixed &...$vars): bool
{
return $this->_instance->bind_param($types,$vars);
}

public function close(): bool
{
return $this->_instance->close();
}
public function data_seek(int $offset): void
{
$this->_instance->data_seek($offset);
}

public function fetch(): ?bool
{
return $this->_instance->fetch();
}
public function free_result(): void
{
$this->_instance->free_result();
}

public function get_result(): \mysqli_result|false
{
return $this->_instance->get_result();
}

public function get_warnings(): \mysqli_warning|false
{
return $this->_instance->get_warnings();
}

public function more_results(): bool
{
return $this->_instance->more_results();
}
public function next_result(): bool
{
return $this->_instance->next_result();
}
public function num_rows(): int|string
{
return $this->_instance->num_rows();
}
public function prepare(string $query): bool
{
return $this->_instance->prepare($query);
}
public function reset(): bool
{
return $this->_instance->reset();
}
public function result_metadata(): \mysqli_result|false
{
return $this->_instance->result_metadata();
}

public function send_long_data(int $param_num, string $data): bool
{
return $this->_instance->send_long_data($param_num,$data);
}

public function store_result(): bool
{
return $this->_instance->store_result();
}

}
}
54 changes: 54 additions & 0 deletions lib/Pinpoint/Plugins/Sys/mysqli7/Mysqli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/******************************************************************************
* Copyright 2020 NAVER Corp. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/
namespace Pinpoint\Plugins\Sys\mysqli7;

class Mysqli extends \mysqli
{
public function prepare ($query)
{
$plugin = new MysqliPreparePlugin("Mysqli::prepare",$this,$query);
try{
$plugin->onBefore();
$ret = parent::prepare($query);
$plugin->onEnd($ret);
return $ret;

}catch (\Exception $e)
{
$plugin->onException($e);
}
}

public function query ($query, $resultmode = NULL)
{
$plugin = new MysqliQueryPlugin("Mysqli::query",$this,$query, $resultmode);
try{
$plugin->onBefore();
$ret = parent::query($query,$resultmode);
$plugin->onEnd($ret);
return $ret;

}catch (\Exception $e)
{
$plugin->onException($e);
}
}
}

function mysqli_init() {
return new Mysqli();
}
37 changes: 37 additions & 0 deletions lib/Pinpoint/Plugins/Sys/mysqli7/MysqliPreparePlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/******************************************************************************
* Copyright 2020 NAVER Corp. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/
namespace Pinpoint\Plugins\Sys\mysqli7;


use Pinpoint\Plugins\Common\PinTrace;

class MysqliPreparePlugin extends PinTrace
{
function onBefore()
{
$myqli = $this->who;
pinpoint_add_clue(PP_SERVER_TYPE,PP_MYSQL);
pinpoint_add_clue(PP_SQL_FORMAT, $this->args[0]);
pinpoint_add_clue(PP_DESTINATION,$myqli->host_info);
}

function onEnd(&$ret)
{
$origin = $ret;
$ret = new ProfilerMysqli_Stmt($origin);
}
}
37 changes: 37 additions & 0 deletions lib/Pinpoint/Plugins/Sys/mysqli7/MysqliQueryPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/******************************************************************************
* Copyright 2020 NAVER Corp. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/
namespace Pinpoint\Plugins\Sys\mysqli7;


use Pinpoint\Plugins\Common\PinTrace;

class MysqliQueryPlugin extends PinTrace
{

function onBefore()
{
$myqli = $this->who;
pinpoint_add_clue(PP_SERVER_TYPE,PP_MYSQL);
pinpoint_add_clue(PP_SQL_FORMAT,$this->args[0]);
pinpoint_add_clue(PP_DESTINATION,$myqli->host_info);
}

function onEnd(&$ret)
{

}
}
32 changes: 32 additions & 0 deletions lib/Pinpoint/Plugins/Sys/mysqli7/ProfilerMysqliResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/******************************************************************************
* Copyright 2020 NAVER Corp. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
******************************************************************************/
namespace Pinpoint\Plugins\Sys\mysqli7;

class ProfilerMysqliResult
{
protected $_instance;
public function __construct(&$instance)
{
$this->_instance = &$instance;
}

public function __call($name, $arguments)
{
return call_user_func_array([&$this->_instance,$name],$arguments);
}

}
Loading

0 comments on commit ada408e

Please sign in to comment.