Commit 48918443 authored by Alex Ne's avatar Alex Ne

Позволение на сипользование null и bool значений в параметрах

parent ea48f59d
......@@ -2,7 +2,6 @@
namespace X\Cache;
class Memcache {
/**
* @var mixed
*/
......@@ -22,7 +21,7 @@ class Memcache {
$this->prefix = $prefix;
$this->mcache = new \memcache();
$this->mcache->connect($host, $port)
@$this->mcache->connect($host, $port)
|| $this->mcache = false;
}
}
......@@ -38,7 +37,7 @@ class Memcache {
}
$key = $this->prefix . $key;
return $this->mcache->set($key, $value, 0, $expire);
return @$this->mcache->set($key, $value, 0, $expire);
}
/**
......@@ -50,7 +49,7 @@ class Memcache {
}
$key = $this->prefix . $key;
return $this->mcache->get($key, 0);
return @$this->mcache->get($key, 0);
}
}
?>
\ No newline at end of file
......@@ -30,8 +30,8 @@
*
*/
namespace X\Database\Driver;
use \X\Database\Credetional as Credetional;
use \X\ETrace\System as ESys;
use X\Database\Credetional as Credetional;
use X\ETrace\System as ESys;
class PDO_CredetionalError extends ESys {}
class PDO_ConnectionError extends ESys {}
......@@ -78,7 +78,7 @@ class PDO {
} catch (\PDOException $e) {
throw new PDO_ConnectionError("Connection to database error", 1, [
"message" => $e->getMessage(),
"info" => $e->errorInfo,
"info" => $e->errorInfo
]);
}
}
......@@ -108,7 +108,7 @@ class PDO {
} else {
throw new PDO_UnknownError("PDO Database Error", 1, [
"SQL" => $SQL,
"error_message" => $e->getMessage(),
"error_message" => $e->getMessage()
]);
}
}
......@@ -142,7 +142,7 @@ class PDO {
} else {
throw new PDO_UnknownError("PDO Database Error", 1, [
"SQL" => $SQL,
"error_message" => $e->getMessage(),
"error_message" => $e->getMessage()
]);
}
}
......@@ -153,7 +153,6 @@ class PDO {
* @param $data
*/
public function insert($table, $data, $replace = false) {
$keys = array_keys($data);
$pattern = array_map(function ($key) {return ":{$key}";}, $keys);
if ($replace) {
......@@ -164,8 +163,12 @@ class PDO {
$SQL = "{$type} INTO `{$table}` (`" . implode('`,`', $keys) . "`) VALUES ( " . implode(", ", $pattern) . " )";
$statement = $this->prepare($SQL);
foreach ($keys as $key) {
$data_bind = $this->check_value($data[$key]);
if (is_integer($data_bind)) {
$data_bind = $data[$key];
if (is_bool($data_bind)) {
$statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_BOOL);
} else if (is_null($data_bind)) {
$statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_NULL);
} else if (is_integer($data_bind)) {
$statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_INT);
} else {
$statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_STR);
......@@ -210,8 +213,12 @@ class PDO {
$SQL .= $whete_obj->get_sql();
$statement = $this->prepare($SQL);
foreach ($keys as $key) {
$data_bind = $this->check_value($data[$key]);
if (is_integer($data_bind)) {
$data_bind = $data[$key];
if (is_bool($data_bind)) {
$statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_BOOL);
} else if (is_null($data_bind)) {
$statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_NULL);
} else if (is_integer($data_bind)) {
$statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_INT);
} else {
$statement->bindValue(":{$key}", $data_bind, \PDO::PARAM_STR);
......@@ -222,7 +229,7 @@ class PDO {
}
public function increment($table, $column, $where = [], $value = 1) {
$SQL = "UPDATE `{$table}` SET `{$column}` = `{$column}` + {$value} ";
$SQL = "UPDATE `{$table}` SET `{$column}` = `{$column}` + {$value} ";
$whete_obj = new PDOWhereConstructor($where);
$SQL .= $whete_obj->get_sql();
$statement = $this->prepare($SQL);
......@@ -231,7 +238,7 @@ class PDO {
}
public function decrement($table, $column, $where = [], $value = 1) {
$SQL = "UPDATE `{$table}` SET `{$column}` = `{$column}` - {$value} ";
$SQL = "UPDATE `{$table}` SET `{$column}` = `{$column}` - {$value} ";
$whete_obj = new PDOWhereConstructor($where);
$SQL .= $whete_obj->get_sql();
$statement = $this->prepare($SQL);
......@@ -347,27 +354,6 @@ class PDO {
}
public function __wakeup() {}
/**
* @param $value
* @return mixed
*/
protected function check_value($value) {
$type = gettype($value);
switch (strtolower($type)) {
case 'boolean':
return $value ? 1 : "0";
break;
case 'null':
return "0";
break;
default:
return $value;
break;
}
}
}
?>
\ No newline at end of file
......@@ -21,7 +21,7 @@
*
*/
namespace X\Database\Driver;
use \X\ETrace\System as ESys;
use X\ETrace\System as ESys;
class PDOWhereConstructor_InputDataTypeError extends ESys {}
class PDOWhereConstructor_OperatorTypeError extends ESys {}
......@@ -69,7 +69,7 @@ class PDOWhereConstructor {
}
} else {
throw new PDOWhereConstructor_InputDataTypeError("Where data must have array type", 1, [
"input_data" => $data,
"input_data" => $data
]);
}
}
......@@ -158,7 +158,7 @@ class PDOWhereConstructor {
if (is_array($data)) {
throw new PDOWhereConstructor_OperatorTypeError("For operator '{$key_info[1]} 'data' must have int or string value'", 1, [
"key" => $key,
"data" => $data,
"data" => $data
]);
}
......@@ -176,7 +176,7 @@ class PDOWhereConstructor {
return [
"type" => $column_type, // column,set
"operator" => $operator, // column = {=,>,<,IN},set= { OR, AND }
"name" => $column_name,
"name" => $column_name
];
}
......@@ -199,34 +199,17 @@ class PDOWhereConstructor {
*/
public function bind(&$statement) {
foreach ($this->data_set as $key => $data_item) {
$data_bind = $this->check_value($data_item);
if (is_integer($data_bind)) {
$data_bind = $data_item;
if (is_bool($data_bind)) {
$statement->bindValue($key, $data_bind, \PDO::PARAM_BOOL);
} else if (is_null($data_bind)) {
$statement->bindValue($key, $data_bind, \PDO::PARAM_NULL);
} else if (is_integer($data_bind)) {
$statement->bindValue($key, $data_bind, \PDO::PARAM_INT);
} else {
$statement->bindValue($key, $data_bind, \PDO::PARAM_STR);
}
}
}
/**
* @param $value
* @return mixed
*/
protected function check_value($value) {
$type = gettype($value);
switch (strtolower($type)) {
case 'boolean':
return $value ? 1 : "0";
break;
case 'null':
return "0";
break;
default:
return $value;
break;
}
}
}
?>
\ No newline at end of file
<?php
namespace X\Social\VK\Method;
use X\Social\VK\VKAPI;
/**
*
*/
class Wall extends VKAPI {
protected $api_version = "5.60";
/**
* https://vk.com/dev/wall.getReposts
*/
public function getReposts($owner_id, $post_id, $offset = 0, $count = 20) {
return $this->check_response($this->api("wall.getReposts", [
"owner_id" => $owner_id,
"post_id" => $post_id,
"offset" => $offset,
"count" => $count,
"v" => $this->api_version
]));
}
/**
* https://vk.com/dev/wall.getById
* @param $posts - Идентификаторы постов
* @param $extended - выводить данные профилей
* @param $copy_history_depth - глубина репостов
* @param $fields
*/
public function getById($posts, $extended = 0, $copy_history_depth = 2, $fields = "") {
return $this->check_response($this->api("wall.getById", [
"posts" => $posts,
"extended" => $extended,
"copy_history_depth" => $copy_history_depth,
"fields" => $fields,
"v" => $this->api_version
]));
}
}
?>
\ No newline at end of file
<?php
namespace X\Social\VK;
class VKAPICredentialsIsNull extends \X\ETrace\System {}
class VKAPIResponseError extends \X\ETrace\System {}
class VKAPIResponseNull extends \X\ETrace\System {}
use X\ETrace\System as ETSystem;
use X\Network\Http\Client as HttpClient;
class VKAPICredentialsIsNull extends ETSystem {}
class VKAPIResponseError extends ETSystem {}
class VKAPIResponseNull extends ETSystem {}
class VKAPI {
/**
* @var \X\Social\VK\Credentials
......@@ -40,7 +43,11 @@ class VKAPI {
* @return array
*/
public function api($method, $params = []) {
return $this->query($this->api_url . "method/" . $method, array_merge($params, ["v" => "5.28"]));
if ( ! isset($params['v'])) {
$params["v"] = "5.28";
}
return $this->query($this->api_url . "method/" . $method, $params);
}
/**
......@@ -49,7 +56,7 @@ class VKAPI {
* @return array
*/
protected function query($url, $params = []) {
$Client = new \X\Network\Http\Client($url);
$Client = new HttpClient($url);
$Client->set_model_data(["post" => $params]);
$ClientResponse = $Client->exec();
if ($data = $ClientResponse->json_decode()) {
......@@ -59,5 +66,17 @@ class VKAPI {
#}
return false;
}
protected function check_response($data) {
if (isset($data["response"])) {
return $data["response"];
}
if (isset($data["error"])) {
throw new VKAPIResponseError($data["error"]["msg"], $data["error"]["code"]);
}
throw new VKAPIResponseNull("VK API response error", 1, ["vk_response" => $data]);
}
}
?>
\ 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 to comment