Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
sinan
mongo-php-library
Commits
d77b7fc2
Commit
d77b7fc2
authored
Jun 15, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create functions.php file for utility functions
parent
9c108d5a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
1 deletion
+82
-1
composer.json
composer.json
+2
-1
functions.php
src/functions.php
+76
-0
PedantryTest.php
tests/PedantryTest.php
+4
-0
No files found.
composer.json
View file @
d77b7fc2
...
...
@@ -13,7 +13,8 @@
"ext-mongodb"
:
">=0.6.0"
},
"autoload"
:
{
"psr-4"
:
{
"MongoDB
\\
"
:
"src/"
}
"psr-4"
:
{
"MongoDB
\\
"
:
"src/"
},
"files"
:
[
"src/functions.php"
]
},
"extra"
:
{
"branch-alias"
:
{
...
...
src/functions.php
0 → 100644
View file @
d77b7fc2
<?php
namespace
MongoDB
;
use
MongoDB\Driver\Server
;
use
MongoDB\Exception\InvalidArgumentTypeException
;
/**
* Return whether the first key in the document starts with a "$" character.
*
* This is used for differentiating update and replacement documents.
*
* @internal
* @param array|object $document Update or replacement document
* @return boolean
* @throws InvalidArgumentTypeException
*/
function
is_first_key_operator
(
$document
)
{
if
(
is_object
(
$document
))
{
$document
=
get_object_vars
(
$document
);
}
if
(
!
is_array
(
$document
))
{
throw
new
InvalidArgumentTypeException
(
'$document'
,
$document
,
'array or object'
);
}
$firstKey
=
(
string
)
key
(
$document
);
return
(
isset
(
$firstKey
[
0
])
&&
$firstKey
[
0
]
==
'$'
);
}
/**
* Generate an index name from a key specification.
*
* @internal
* @param array|object $document Document containing fields mapped to values,
* which denote order or an index type
* @return string
* @throws InvalidArgumentTypeException
*/
function
generate_index_name
(
$document
)
{
if
(
is_object
(
$document
))
{
$document
=
get_object_vars
(
$document
);
}
if
(
!
is_array
(
$document
))
{
throw
new
InvalidArgumentTypeException
(
'$document'
,
$document
,
'array or object'
);
}
$name
=
''
;
foreach
(
$document
as
$field
=>
$type
)
{
$name
.=
(
$name
!=
''
?
'_'
:
''
)
.
$field
.
'_'
.
$type
;
}
return
$name
;
}
/**
* Return whether the server supports a particular feature.
*
* @internal
* @param Server $server Server to check
* @param integer $feature Feature constant (i.e. wire protocol version)
* @return boolean
*/
function
server_supports_feature
(
Server
$server
,
$feature
)
{
$info
=
$server
->
getInfo
();
$maxWireVersion
=
isset
(
$info
[
'maxWireVersion'
])
?
(
integer
)
$info
[
'maxWireVersion'
]
:
0
;
$minWireVersion
=
isset
(
$info
[
'minWireVersion'
])
?
(
integer
)
$info
[
'minWireVersion'
]
:
0
;
return
(
$minWireVersion
<=
$feature
&&
$maxWireVersion
>=
$feature
);
}
tests/PedantryTest.php
View file @
d77b7fc2
...
...
@@ -62,6 +62,10 @@ class PedantryTest extends \PHPUnit_Framework_TestCase
$files
=
new
RegexIterator
(
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$srcDir
)),
'/\.php$/i'
);
foreach
(
$files
as
$file
)
{
if
(
$file
->
getFilename
()
===
'functions.php'
)
{
continue
;
}
$classNames
[][]
=
'MongoDB\\'
.
str_replace
(
DIRECTORY_SEPARATOR
,
'\\'
,
substr
(
$file
->
getRealPath
(),
strlen
(
$srcDir
)
+
1
,
-
4
));
}
...
...
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