Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
PHP-MySQLi-Database-Class
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
PHP-MySQLi-Database-Class
Commits
66fb6818
Commit
66fb6818
authored
May 31, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validation expanded
parent
851dcfe2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
11 deletions
+24
-11
dbObject.php
dbObject.php
+10
-5
dbObjectTests.php
tests/dbObjectTests.php
+14
-6
No files found.
dbObject.php
View file @
66fb6818
...
...
@@ -462,7 +462,6 @@ class dbObject {
* @param array $data
*/
private
function
validate
(
$data
)
{
$this
->
errors
=
Array
();
foreach
(
$this
->
dbFields
as
$key
=>
$desc
)
{
$type
=
null
;
$required
=
false
;
...
...
@@ -480,7 +479,7 @@ class dbObject {
$required
=
true
;
if
(
$required
&&
strlen
(
$value
)
==
0
)
{
$this
->
errors
[]
=
Array
(
$key
=>
"is required"
);
$this
->
errors
[]
=
Array
(
$
this
->
dbTable
.
"."
.
$
key
=>
"is required"
);
continue
;
}
if
(
$value
==
null
)
...
...
@@ -507,7 +506,7 @@ class dbObject {
continue
;
if
(
!
preg_match
(
$regexp
,
$value
))
{
$this
->
errors
[]
=
Array
(
$key
=>
"
$type
validation failed"
);
$this
->
errors
[]
=
Array
(
$
this
->
dbTable
.
"."
.
$
key
=>
"
$type
validation failed"
);
continue
;
}
}
...
...
@@ -515,6 +514,7 @@ class dbObject {
}
private
function
prepareData
()
{
$this
->
errors
=
Array
();
$sqlData
=
Array
();
if
(
count
(
$this
->
data
)
==
0
)
return
Array
();
...
...
@@ -523,8 +523,13 @@ class dbObject {
$this
->
preLoad
(
$data
);
foreach
(
$this
->
data
as
$key
=>
&
$value
)
{
if
(
$value
instanceof
dbObject
&&
$value
->
isNew
==
true
)
$value
=
$value
->
save
();
if
(
$value
instanceof
dbObject
&&
$value
->
isNew
==
true
)
{
$id
=
$value
->
save
();
if
(
$id
)
$value
=
$id
;
else
$this
->
errors
=
array_merge
(
$this
->
errors
,
$value
->
errors
);
}
if
(
!
in_array
(
$key
,
array_keys
(
$this
->
dbFields
)))
continue
;
...
...
tests/dbObjectTests.php
View file @
66fb6818
<?
error_reporting
(
E_STRICT
);
require_once
(
"../MysqliDb.php"
);
require_once
(
"../dbObject.php"
);
require_once
(
"models/product.php"
);
...
...
@@ -98,6 +99,7 @@ foreach ($data as $name => $datas) {
$obj
=
new
$name
(
$userData
);
$id
=
$obj
->
save
();
if
(
$obj
->
errors
)
{
echo
"errors:"
;
print_r
(
$obj
->
errors
);
exit
;
}
...
...
@@ -196,6 +198,7 @@ $obj->save();
$obj
->
userId
=
$client
;
$obj
->
save
();
if
(
$client
->
errors
)
{
echo
"errors:"
;
print_r
(
$client
->
errors
);
exit
;
}
...
...
@@ -208,16 +211,21 @@ if ($obj->with('userId')->toJson() != $expected) {
exit
;
}
$obj
=
new
user
;
$obj
->
active
=
'test'
;
$obj
->
customerId
=
'test'
;
$obj
->
expires
=
'test;'
;
$obj
->
firstName
=
'test'
;
$u
=
new
user
;
$u
->
active
=
'test'
;
$u
->
customerId
=
'test'
;
$u
->
expires
=
'test;'
;
$u
->
firstName
=
'test'
;
$obj
=
new
product
;
$obj
->
userId
=
$u
;
$obj
->
save
();
if
(
$obj
->
save
())
{
echo
"validation 1 failed
\n
"
;
exit
;
}
if
(
count
(
$obj
->
errors
)
!=
4
)
{
if
(
count
(
$obj
->
errors
)
!=
7
)
{
print_r
(
$obj
->
errors
);
echo
"validation 2 failed
\n
"
;
exit
;
}
...
...
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