Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
X Lib
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
XLibs
X Lib
Commits
48918443
Commit
48918443
authored
Dec 22, 2016
by
Alex Ne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Позволение на сипользование null и bool значений в параметрах
parent
ea48f59d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
69 deletions
+96
-69
Memcache.php
Cache/Memcache.php
+3
-4
PDO.php
Database/Driver/PDO.php
+19
-33
PDOWhereConstructor.php
Database/Driver/PDOWhereConstructor.php
+10
-27
Wall.php
Social/VK/Method/Wall.php
+40
-0
VKAPI.php
Social/VK/VKAPI.php
+24
-5
No files found.
Cache/Memcache.php
View file @
48918443
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
namespace
X\Cache
;
namespace
X\Cache
;
class
Memcache
{
class
Memcache
{
/**
/**
* @var mixed
* @var mixed
*/
*/
...
@@ -22,7 +21,7 @@ class Memcache {
...
@@ -22,7 +21,7 @@ class Memcache {
$this
->
prefix
=
$prefix
;
$this
->
prefix
=
$prefix
;
$this
->
mcache
=
new
\memcache
();
$this
->
mcache
=
new
\memcache
();
$this
->
mcache
->
connect
(
$host
,
$port
)
@
$this
->
mcache
->
connect
(
$host
,
$port
)
||
$this
->
mcache
=
false
;
||
$this
->
mcache
=
false
;
}
}
}
}
...
@@ -38,7 +37,7 @@ class Memcache {
...
@@ -38,7 +37,7 @@ class Memcache {
}
}
$key
=
$this
->
prefix
.
$key
;
$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 {
...
@@ -50,7 +49,7 @@ class Memcache {
}
}
$key
=
$this
->
prefix
.
$key
;
$key
=
$this
->
prefix
.
$key
;
return
$this
->
mcache
->
get
(
$key
,
0
);
return
@
$this
->
mcache
->
get
(
$key
,
0
);
}
}
}
}
?>
?>
\ No newline at end of file
Database/Driver/PDO.php
View file @
48918443
...
@@ -30,8 +30,8 @@
...
@@ -30,8 +30,8 @@
*
*
*/
*/
namespace
X\Database\Driver
;
namespace
X\Database\Driver
;
use
\
X\Database\Credetional
as
Credetional
;
use
X\Database\Credetional
as
Credetional
;
use
\
X\ETrace\System
as
ESys
;
use
X\ETrace\System
as
ESys
;
class
PDO_CredetionalError
extends
ESys
{}
class
PDO_CredetionalError
extends
ESys
{}
class
PDO_ConnectionError
extends
ESys
{}
class
PDO_ConnectionError
extends
ESys
{}
...
@@ -78,7 +78,7 @@ class PDO {
...
@@ -78,7 +78,7 @@ class PDO {
}
catch
(
\PDOException
$e
)
{
}
catch
(
\PDOException
$e
)
{
throw
new
PDO_ConnectionError
(
"Connection to database error"
,
1
,
[
throw
new
PDO_ConnectionError
(
"Connection to database error"
,
1
,
[
"message"
=>
$e
->
getMessage
(),
"message"
=>
$e
->
getMessage
(),
"info"
=>
$e
->
errorInfo
,
"info"
=>
$e
->
errorInfo
]);
]);
}
}
}
}
...
@@ -108,7 +108,7 @@ class PDO {
...
@@ -108,7 +108,7 @@ class PDO {
}
else
{
}
else
{
throw
new
PDO_UnknownError
(
"PDO Database Error"
,
1
,
[
throw
new
PDO_UnknownError
(
"PDO Database Error"
,
1
,
[
"SQL"
=>
$SQL
,
"SQL"
=>
$SQL
,
"error_message"
=>
$e
->
getMessage
()
,
"error_message"
=>
$e
->
getMessage
()
]);
]);
}
}
}
}
...
@@ -142,7 +142,7 @@ class PDO {
...
@@ -142,7 +142,7 @@ class PDO {
}
else
{
}
else
{
throw
new
PDO_UnknownError
(
"PDO Database Error"
,
1
,
[
throw
new
PDO_UnknownError
(
"PDO Database Error"
,
1
,
[
"SQL"
=>
$SQL
,
"SQL"
=>
$SQL
,
"error_message"
=>
$e
->
getMessage
()
,
"error_message"
=>
$e
->
getMessage
()
]);
]);
}
}
}
}
...
@@ -153,7 +153,6 @@ class PDO {
...
@@ -153,7 +153,6 @@ class PDO {
* @param $data
* @param $data
*/
*/
public
function
insert
(
$table
,
$data
,
$replace
=
false
)
{
public
function
insert
(
$table
,
$data
,
$replace
=
false
)
{
$keys
=
array_keys
(
$data
);
$keys
=
array_keys
(
$data
);
$pattern
=
array_map
(
function
(
$key
)
{
return
":
{
$key
}
"
;},
$keys
);
$pattern
=
array_map
(
function
(
$key
)
{
return
":
{
$key
}
"
;},
$keys
);
if
(
$replace
)
{
if
(
$replace
)
{
...
@@ -164,8 +163,12 @@ class PDO {
...
@@ -164,8 +163,12 @@ class PDO {
$SQL
=
"
{
$type
}
INTO `
{
$table
}
` (`"
.
implode
(
'`,`'
,
$keys
)
.
"`) VALUES ( "
.
implode
(
", "
,
$pattern
)
.
" )"
;
$SQL
=
"
{
$type
}
INTO `
{
$table
}
` (`"
.
implode
(
'`,`'
,
$keys
)
.
"`) VALUES ( "
.
implode
(
", "
,
$pattern
)
.
" )"
;
$statement
=
$this
->
prepare
(
$SQL
);
$statement
=
$this
->
prepare
(
$SQL
);
foreach
(
$keys
as
$key
)
{
foreach
(
$keys
as
$key
)
{
$data_bind
=
$this
->
check_value
(
$data
[
$key
]);
$data_bind
=
$data
[
$key
];
if
(
is_integer
(
$data_bind
))
{
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
);
$statement
->
bindValue
(
":
{
$key
}
"
,
$data_bind
,
\PDO
::
PARAM_INT
);
}
else
{
}
else
{
$statement
->
bindValue
(
":
{
$key
}
"
,
$data_bind
,
\PDO
::
PARAM_STR
);
$statement
->
bindValue
(
":
{
$key
}
"
,
$data_bind
,
\PDO
::
PARAM_STR
);
...
@@ -210,8 +213,12 @@ class PDO {
...
@@ -210,8 +213,12 @@ class PDO {
$SQL
.=
$whete_obj
->
get_sql
();
$SQL
.=
$whete_obj
->
get_sql
();
$statement
=
$this
->
prepare
(
$SQL
);
$statement
=
$this
->
prepare
(
$SQL
);
foreach
(
$keys
as
$key
)
{
foreach
(
$keys
as
$key
)
{
$data_bind
=
$this
->
check_value
(
$data
[
$key
]);
$data_bind
=
$data
[
$key
];
if
(
is_integer
(
$data_bind
))
{
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
);
$statement
->
bindValue
(
":
{
$key
}
"
,
$data_bind
,
\PDO
::
PARAM_INT
);
}
else
{
}
else
{
$statement
->
bindValue
(
":
{
$key
}
"
,
$data_bind
,
\PDO
::
PARAM_STR
);
$statement
->
bindValue
(
":
{
$key
}
"
,
$data_bind
,
\PDO
::
PARAM_STR
);
...
@@ -222,7 +229,7 @@ class PDO {
...
@@ -222,7 +229,7 @@ class PDO {
}
}
public
function
increment
(
$table
,
$column
,
$where
=
[],
$value
=
1
)
{
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
);
$whete_obj
=
new
PDOWhereConstructor
(
$where
);
$SQL
.=
$whete_obj
->
get_sql
();
$SQL
.=
$whete_obj
->
get_sql
();
$statement
=
$this
->
prepare
(
$SQL
);
$statement
=
$this
->
prepare
(
$SQL
);
...
@@ -231,7 +238,7 @@ class PDO {
...
@@ -231,7 +238,7 @@ class PDO {
}
}
public
function
decrement
(
$table
,
$column
,
$where
=
[],
$value
=
1
)
{
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
);
$whete_obj
=
new
PDOWhereConstructor
(
$where
);
$SQL
.=
$whete_obj
->
get_sql
();
$SQL
.=
$whete_obj
->
get_sql
();
$statement
=
$this
->
prepare
(
$SQL
);
$statement
=
$this
->
prepare
(
$SQL
);
...
@@ -347,27 +354,6 @@ class PDO {
...
@@ -347,27 +354,6 @@ class PDO {
}
}
public
function
__wakeup
()
{}
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
Database/Driver/PDOWhereConstructor.php
View file @
48918443
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
*
*
*/
*/
namespace
X\Database\Driver
;
namespace
X\Database\Driver
;
use
\
X\ETrace\System
as
ESys
;
use
X\ETrace\System
as
ESys
;
class
PDOWhereConstructor_InputDataTypeError
extends
ESys
{}
class
PDOWhereConstructor_InputDataTypeError
extends
ESys
{}
class
PDOWhereConstructor_OperatorTypeError
extends
ESys
{}
class
PDOWhereConstructor_OperatorTypeError
extends
ESys
{}
...
@@ -69,7 +69,7 @@ class PDOWhereConstructor {
...
@@ -69,7 +69,7 @@ class PDOWhereConstructor {
}
}
}
else
{
}
else
{
throw
new
PDOWhereConstructor_InputDataTypeError
(
"Where data must have array type"
,
1
,
[
throw
new
PDOWhereConstructor_InputDataTypeError
(
"Where data must have array type"
,
1
,
[
"input_data"
=>
$data
,
"input_data"
=>
$data
]);
]);
}
}
}
}
...
@@ -158,7 +158,7 @@ class PDOWhereConstructor {
...
@@ -158,7 +158,7 @@ class PDOWhereConstructor {
if
(
is_array
(
$data
))
{
if
(
is_array
(
$data
))
{
throw
new
PDOWhereConstructor_OperatorTypeError
(
"For operator '
{
$key_info
[
1
]
}
'data' must have int or string value'"
,
1
,
[
throw
new
PDOWhereConstructor_OperatorTypeError
(
"For operator '
{
$key_info
[
1
]
}
'data' must have int or string value'"
,
1
,
[
"key"
=>
$key
,
"key"
=>
$key
,
"data"
=>
$data
,
"data"
=>
$data
]);
]);
}
}
...
@@ -176,7 +176,7 @@ class PDOWhereConstructor {
...
@@ -176,7 +176,7 @@ class PDOWhereConstructor {
return
[
return
[
"type"
=>
$column_type
,
// column,set
"type"
=>
$column_type
,
// column,set
"operator"
=>
$operator
,
// column = {=,>,<,IN},set= { OR, AND }
"operator"
=>
$operator
,
// column = {=,>,<,IN},set= { OR, AND }
"name"
=>
$column_name
,
"name"
=>
$column_name
];
];
}
}
...
@@ -199,34 +199,17 @@ class PDOWhereConstructor {
...
@@ -199,34 +199,17 @@ class PDOWhereConstructor {
*/
*/
public
function
bind
(
&
$statement
)
{
public
function
bind
(
&
$statement
)
{
foreach
(
$this
->
data_set
as
$key
=>
$data_item
)
{
foreach
(
$this
->
data_set
as
$key
=>
$data_item
)
{
$data_bind
=
$this
->
check_value
(
$data_item
);
$data_bind
=
$data_item
;
if
(
is_integer
(
$data_bind
))
{
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
);
$statement
->
bindValue
(
$key
,
$data_bind
,
\PDO
::
PARAM_INT
);
}
else
{
}
else
{
$statement
->
bindValue
(
$key
,
$data_bind
,
\PDO
::
PARAM_STR
);
$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
Social/VK/Method/Wall.php
0 → 100644
View file @
48918443
<?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
Social/VK/VKAPI.php
View file @
48918443
<?php
<?php
namespace
X\Social\VK
;
namespace
X\Social\VK
;
class
VKAPICredentialsIsNull
extends
\X\ETrace\System
{}
use
X\ETrace\System
as
ETSystem
;
class
VKAPIResponseError
extends
\X\ETrace\System
{}
use
X\Network\Http\Client
as
HttpClient
;
class
VKAPIResponseNull
extends
\X\ETrace\System
{}
class
VKAPICredentialsIsNull
extends
ETSystem
{}
class
VKAPIResponseError
extends
ETSystem
{}
class
VKAPIResponseNull
extends
ETSystem
{}
class
VKAPI
{
class
VKAPI
{
/**
/**
* @var \X\Social\VK\Credentials
* @var \X\Social\VK\Credentials
...
@@ -40,7 +43,11 @@ class VKAPI {
...
@@ -40,7 +43,11 @@ class VKAPI {
* @return array
* @return array
*/
*/
public
function
api
(
$method
,
$params
=
[])
{
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 {
...
@@ -49,7 +56,7 @@ class VKAPI {
* @return array
* @return array
*/
*/
protected
function
query
(
$url
,
$params
=
[])
{
protected
function
query
(
$url
,
$params
=
[])
{
$Client
=
new
\X\Network\Http\
Client
(
$url
);
$Client
=
new
Http
Client
(
$url
);
$Client
->
set_model_data
([
"post"
=>
$params
]);
$Client
->
set_model_data
([
"post"
=>
$params
]);
$ClientResponse
=
$Client
->
exec
();
$ClientResponse
=
$Client
->
exec
();
if
(
$data
=
$ClientResponse
->
json_decode
())
{
if
(
$data
=
$ClientResponse
->
json_decode
())
{
...
@@ -59,5 +66,17 @@ class VKAPI {
...
@@ -59,5 +66,17 @@ class VKAPI {
#}
#}
return
false
;
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment