Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marcus Eibrink-Lunzenauer
Stud.IP
Commits
b71f3e84
Commit
b71f3e84
authored
3 years ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
replace all mb_* calls with their non multibyte version, fixes #398
parent
f652829c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/models/SimpleORMap.class.php
+48
-46
48 additions, 46 deletions
lib/models/SimpleORMap.class.php
with
48 additions
and
46 deletions
lib/models/SimpleORMap.class.php
+
48
−
46
View file @
b71f3e84
...
...
@@ -190,7 +190,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
$class
=
get_called_class
();
if
(
empty
(
$config
[
'db_table'
]))
{
$config
[
'db_table'
]
=
mb_
strtolower
(
$class
);
$config
[
'db_table'
]
=
strtolower
(
$class
);
}
if
(
!
isset
(
$config
[
'db_fields'
]))
{
...
...
@@ -280,7 +280,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
foreach
(
$auto_notification_map
as
$cb
=>
$notification
)
{
if
(
isset
(
$config
[
'notification_map'
][
$cb
]))
{
if
(
mb_
strpos
(
$config
[
'notification_map'
][
$cb
],
$notification
)
!==
false
)
{
if
(
strpos
(
$config
[
'notification_map'
][
$cb
],
$notification
)
!==
false
)
{
$config
[
'notification_map'
][
$cb
]
.
=
' '
.
$notification
;
}
}
else
{
...
...
@@ -312,10 +312,10 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
array_keys
(
$config
[
'relations'
]
?:
[])
);
foreach
(
array_map
(
'
mb_
strtolower'
,
get_class_methods
(
$class
))
as
$method
)
{
if
(
in_array
(
mb_
substr
(
$method
,
0
,
3
),
[
'get'
,
'set'
]))
{
$verb
=
mb_
substr
(
$method
,
0
,
3
);
$name
=
mb_
substr
(
$method
,
3
);
foreach
(
array_map
(
'strtolower'
,
get_class_methods
(
$class
))
as
$method
)
{
if
(
in_array
(
substr
(
$method
,
0
,
3
),
[
'get'
,
'set'
]))
{
$verb
=
substr
(
$method
,
0
,
3
);
$name
=
substr
(
$method
,
3
);
if
(
in_array
(
$name
,
$config
[
'known_slots'
])
&&
!
in_array
(
$name
,
static
::
$reserved_slots
)
&&
!
isset
(
$config
[
'additional_fields'
][
$name
][
$verb
]))
{
$config
[
'getter_setter_map'
][
$name
][
$verb
]
=
$method
;
}
...
...
@@ -354,15 +354,15 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
if
(
!
isset
(
self
::
$schemes
[
$db_table
]))
{
$db
=
DBManager
::
get
()
->
query
(
"SHOW COLUMNS FROM
$db_table
"
);
while
(
$rs
=
$db
->
fetch
(
PDO
::
FETCH_ASSOC
)){
$db_fields
[
mb_
strtolower
(
$rs
[
'Field'
])]
=
[
'name'
=>
$rs
[
'Field'
],
'null'
=>
$rs
[
'Null'
],
'default'
=>
$rs
[
'Default'
],
'type'
=>
$rs
[
'Type'
],
'extra'
=>
$rs
[
'Extra'
]
];
$db_fields
[
strtolower
(
$rs
[
'Field'
])]
=
[
'name'
=>
$rs
[
'Field'
],
'null'
=>
$rs
[
'Null'
],
'default'
=>
$rs
[
'Default'
],
'type'
=>
$rs
[
'Type'
],
'extra'
=>
$rs
[
'Extra'
]
];
if
(
$rs
[
'Key'
]
==
'PRI'
){
$pk
[]
=
mb_
strtolower
(
$rs
[
'Field'
]);
$pk
[]
=
strtolower
(
$rs
[
'Field'
]);
}
}
self
::
$schemes
[
$db_table
][
'db_fields'
]
=
$db_fields
;
...
...
@@ -434,7 +434,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
{
$db_table
=
static
::
config
(
'db_table'
);
$db
=
DBManager
::
get
();
$has_join
=
mb_
stripos
(
$sql
,
'JOIN '
);
$has_join
=
stripos
(
$sql
,
'JOIN '
);
if
(
$has_join
===
false
||
$has_join
>
10
)
{
$sql
=
'WHERE '
.
$sql
;
}
...
...
@@ -558,7 +558,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
$class
=
get_called_class
();
$record
=
new
$class
();
$db
=
DBManager
::
get
();
$has_join
=
mb_
stripos
(
$sql
,
'JOIN '
);
$has_join
=
stripos
(
$sql
,
'JOIN '
);
if
(
$has_join
===
false
||
$has_join
>
10
)
{
$sql
=
'WHERE '
.
$sql
;
}
...
...
@@ -587,7 +587,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
public
static
function
findOneBySQL
(
$where
,
$params
=
[])
{
if
(
mb_
stripos
(
$where
,
'LIMIT'
)
===
false
)
{
if
(
stripos
(
$where
,
'LIMIT'
)
===
false
)
{
$where
.
=
" LIMIT 1"
;
}
$found
=
static
::
findBySQL
(
$where
,
$params
);
...
...
@@ -641,7 +641,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
public
static
function
findEachBySQL
(
$callable
,
$sql
,
$params
=
[])
{
$has_join
=
mb_
stripos
(
$sql
,
'JOIN '
);
$has_join
=
stripos
(
$sql
,
'JOIN '
);
if
(
$has_join
===
false
||
$has_join
>
10
)
{
$sql
=
"WHERE
{
$sql
}
"
;
}
...
...
@@ -816,13 +816,13 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
$db_table
=
static
::
config
(
'db_table'
);
$alias_fields
=
static
::
config
(
'alias_fields'
);
$db_fields
=
static
::
config
(
'db_fields'
);
$name
=
mb_
strtolower
(
$name
);
$name
=
strtolower
(
$name
);
$class
=
get_called_class
();
$param_arr
=
[];
$where
=
''
;
$where_param
=
is_array
(
$arguments
[
0
])
?
$arguments
[
0
]
:
[
$arguments
[
0
]];
$prefix
=
mb_
strstr
(
$name
,
'by'
,
true
);
$field
=
mb_
substr
(
$name
,
mb_
strlen
(
$prefix
)
+
2
);
$prefix
=
strstr
(
$name
,
'by'
,
true
);
$field
=
substr
(
$name
,
strlen
(
$prefix
)
+
2
);
switch
(
$prefix
)
{
case
'findone'
:
$order
=
$arguments
[
1
];
...
...
@@ -1224,7 +1224,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
$fields
=
array_diff
(
$this
->
known_slots
,
array_keys
(
$this
->
relations
));
if
(
is_array
(
$only_these_fields
))
{
$only_these_fields
=
array_filter
(
array_map
(
function
(
$s
)
{
return
is_string
(
$s
)
?
mb_
strtolower
(
$s
)
:
null
;
return
is_string
(
$s
)
?
strtolower
(
$s
)
:
null
;
},
$only_these_fields
));
$fields
=
array_intersect
(
$only_these_fields
,
$fields
);
}
...
...
@@ -1254,8 +1254,8 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
}
$fields
=
array_keys
(
$this
->
db_fields
);
if
(
is_array
(
$only_these_fields
))
{
$only_these_fields
=
array_filter
(
array_map
(
function
(
$s
)
{
return
is_string
(
$s
)
?
mb_
strtolower
(
$s
)
:
null
;
$only_these_fields
=
array_filter
(
array_map
(
function
(
$s
)
{
return
is_string
(
$s
)
?
strtolower
(
$s
)
:
null
;
},
$only_these_fields
));
$fields
=
array_intersect
(
$only_these_fields
,
$fields
);
}
...
...
@@ -1304,11 +1304,12 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
if
(
is_array
(
$only_these_fields
))
{
foreach
(
$only_these_fields
as
$key
=>
$value
)
{
if
(
!
is_array
(
$value
)
&&
array_key_exists
(
mb_strtolower
(
$value
),
$this
->
relations
))
{
$relations
[
mb_strtolower
(
$value
)]
=
0
;
//not null|array|string to stop recursion
array_key_exists
(
strtolower
(
$value
),
$this
->
relations
)
)
{
$relations
[
strtolower
(
$value
)]
=
0
;
//not null|array|string to stop recursion
}
if
(
array_key_exists
(
mb_
strtolower
(
$key
),
$this
->
relations
))
{
$relations
[
mb_
strtolower
(
$key
)]
=
$value
;
if
(
array_key_exists
(
strtolower
(
$key
),
$this
->
relations
))
{
$relations
[
strtolower
(
$key
)]
=
$value
;
}
}
}
...
...
@@ -1343,7 +1344,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
public
function
getValue
(
$field
)
{
$field
=
mb_
strtolower
(
$field
);
$field
=
strtolower
(
$field
);
// No value defined, throw exception
if
(
!
in_array
(
$field
,
$this
->
known_slots
))
{
...
...
@@ -1393,7 +1394,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
function
getRelationValue
(
$relation
,
$field
)
{
$field
=
mb_
strtolower
(
$field
);
$field
=
strtolower
(
$field
);
$options
=
$this
->
getRelationOptions
(
$relation
);
if
(
$options
[
'type'
]
===
'has_one'
||
$options
[
'type'
]
===
'belongs_to'
)
{
return
$this
->
{
$relation
}
->
{
$field
};
...
...
@@ -1417,10 +1418,10 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
if
(
isset
(
$meta
[
'default'
]))
{
$default_value
=
$meta
[
'default'
];
}
elseif
(
$meta
[
'null'
]
==
'NO'
)
{
if
(
mb_
strpos
(
$meta
[
'type'
],
'text'
)
!==
false
||
mb_
strpos
(
$meta
[
'type'
],
'char'
)
!==
false
)
{
if
(
strpos
(
$meta
[
'type'
],
'text'
)
!==
false
||
strpos
(
$meta
[
'type'
],
'char'
)
!==
false
)
{
$default_value
=
''
;
}
if
(
mb_
strpos
(
$meta
[
'type'
],
'int'
)
!==
false
)
{
if
(
strpos
(
$meta
[
'type'
],
'int'
)
!==
false
)
{
$default_value
=
'0'
;
}
}
...
...
@@ -1442,7 +1443,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
function
setValue
(
$field
,
$value
)
{
$field
=
mb_
strtolower
(
$field
);
$field
=
strtolower
(
$field
);
$ret
=
false
;
if
(
in_array
(
$field
,
$this
->
known_slots
))
{
if
(
isset
(
$this
->
getter_setter_map
[
$field
][
'set'
]))
{
...
...
@@ -1538,7 +1539,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
function
__isset
(
$field
)
{
$field
=
mb_
strtolower
(
$field
);
$field
=
strtolower
(
$field
);
if
(
in_array
(
$field
,
$this
->
known_slots
))
{
$value
=
$this
->
getValue
(
$field
);
return
$value
instanceOf
SimpleORMapCollection
?
(
bool
)
count
(
$value
)
:
!
is_null
(
$value
);
...
...
@@ -1598,7 +1599,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
function
isField
(
$field
)
{
$field
=
mb_
strtolower
(
$field
);
$field
=
strtolower
(
$field
);
return
isset
(
$this
->
db_fields
[
$field
]);
}
...
...
@@ -1609,7 +1610,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
function
isAdditionalField
(
$field
)
{
$field
=
mb_
strtolower
(
$field
);
$field
=
strtolower
(
$field
);
return
isset
(
$this
->
additional_fields
[
$field
]);
}
...
...
@@ -1620,7 +1621,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
function
isAliasField
(
$field
)
{
$field
=
mb_
strtolower
(
$field
);
$field
=
strtolower
(
$field
);
return
isset
(
$this
->
alias_fields
[
$field
]);
}
...
...
@@ -1631,7 +1632,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
function
isI18nField
(
$field
)
{
$field
=
mb_
strtolower
(
$field
);
$field
=
strtolower
(
$field
);
return
isset
(
$this
->
i18n_fields
[
$field
]);
}
...
...
@@ -1656,10 +1657,11 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
}
if
(
is_array
(
$data
)
||
$data
instanceof
Traversable
)
{
foreach
(
$data
as
$key
=>
$value
)
{
$key
=
mb_
strtolower
(
$key
);
$key
=
strtolower
(
$key
);
if
(
isset
(
$this
->
db_fields
[
$key
])
||
isset
(
$this
->
alias_fields
[
$key
])
||
isset
(
$this
->
additional_fields
[
$key
][
'set'
]))
{
||
isset
(
$this
->
alias_fields
[
$key
])
||
isset
(
$this
->
additional_fields
[
$key
][
'set'
])
)
{
$this
->
setValue
(
$key
,
$value
);
++
$count
;
}
...
...
@@ -1841,8 +1843,8 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
}
$relations
=
array_keys
(
$this
->
relations
);
if
(
is_array
(
$only_these
))
{
$only_these
=
array_filter
(
array_map
(
function
(
$s
)
{
return
is_string
(
$s
)
?
mb_
strtolower
(
$s
)
:
null
;
$only_these
=
array_filter
(
array_map
(
function
(
$s
)
{
return
is_string
(
$s
)
?
strtolower
(
$s
)
:
null
;
},
$only_these
));
$relations
=
array_intersect
(
$only_these
,
$relations
);
}
...
...
@@ -2024,7 +2026,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
public
function
isFieldDirty
(
$field
)
{
$field
=
mb_
strtolower
(
$field
);
$field
=
strtolower
(
$field
);
if
(
$this
->
content
[
$field
]
===
null
||
$this
->
content_db
[
$field
]
===
null
)
{
return
$this
->
content
[
$field
]
!==
$this
->
content_db
[
$field
];
}
else
if
(
$this
->
content
[
$field
]
instanceof
I18NString
||
$this
->
content_db
[
$field
]
instanceof
I18NString
)
{
...
...
@@ -2042,7 +2044,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
public
function
revertValue
(
$field
)
{
$field
=
mb_
strtolower
(
$field
);
$field
=
strtolower
(
$field
);
return
(
$this
->
content
[
$field
]
=
$this
->
content_db
[
$field
]);
}
...
...
@@ -2055,7 +2057,7 @@ class SimpleORMap implements ArrayAccess, Countable, IteratorAggregate
*/
public
function
getPristineValue
(
$field
)
{
$field
=
mb_
strtolower
(
$field
);
$field
=
strtolower
(
$field
);
if
(
array_key_exists
(
$field
,
$this
->
content_db
))
{
return
$this
->
content_db
[
$field
];
}
else
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment