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
1e3be59e
Commit
1e3be59e
authored
Sep 12, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #240
parents
a0e53eb6
96284ef8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
9 deletions
+49
-9
Bucket.php
src/GridFS/Bucket.php
+37
-9
BucketFunctionalTest.php
tests/GridFS/BucketFunctionalTest.php
+12
-0
No files found.
src/GridFS/Bucket.php
View file @
1e3be59e
...
...
@@ -21,12 +21,14 @@ use stdClass;
*/
class
Bucket
{
private
static
$defaultBucketName
=
'fs'
;
private
static
$defaultChunkSizeBytes
=
261120
;
private
static
$streamWrapperProtocol
=
'gridfs'
;
private
$collectionWrapper
;
private
$databaseName
;
private
$options
;
private
$bucketName
;
private
$chunkSizeBytes
;
/**
* Constructs a GridFS bucket.
...
...
@@ -53,7 +55,7 @@ class Bucket
public
function
__construct
(
Manager
$manager
,
$databaseName
,
array
$options
=
[])
{
$options
+=
[
'bucketName'
=>
'fs'
,
'bucketName'
=>
self
::
$defaultBucketName
,
'chunkSizeBytes'
=>
self
::
$defaultChunkSizeBytes
,
];
...
...
@@ -78,7 +80,8 @@ class Bucket
}
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
options
=
$options
;
$this
->
bucketName
=
$options
[
'bucketName'
];
$this
->
chunkSizeBytes
=
$options
[
'chunkSizeBytes'
];
$collectionOptions
=
array_intersect_key
(
$options
,
[
'readConcern'
=>
1
,
'readPreference'
=>
1
,
'writeConcern'
=>
1
]);
...
...
@@ -86,6 +89,21 @@ class Bucket
$this
->
registerStreamWrapper
();
}
/**
* Return internal properties for debugging purposes.
*
* @see http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
* @return array
*/
public
function
__debugInfo
()
{
return
[
'bucketName'
=>
$this
->
bucketName
,
'databaseName'
=>
$this
->
databaseName
,
'chunkSizeBytes'
=>
$this
->
chunkSizeBytes
,
];
}
/**
* Delete a file from the GridFS bucket.
*
...
...
@@ -179,11 +197,21 @@ class Bucket
return
$this
->
collectionWrapper
->
findFiles
(
$filter
,
$options
);
}
public
function
getCollectionWrapper
()
/**
* Return the bucket name.
*
* @return string
*/
public
function
getBucketName
()
{
return
$this
->
collectionWrapper
;
return
$this
->
bucketName
;
}
/**
* Return the database name.
*
* @return string
*/
public
function
getDatabaseName
()
{
return
$this
->
databaseName
;
...
...
@@ -280,7 +308,7 @@ class Bucket
*/
public
function
openUploadStream
(
$filename
,
array
$options
=
[])
{
$options
+=
[
'chunkSizeBytes'
=>
$this
->
options
[
'chunkSizeBytes'
]
];
$options
+=
[
'chunkSizeBytes'
=>
$this
->
chunkSizeBytes
];
$path
=
$this
->
createPathForUpload
();
$context
=
stream_context_create
([
...
...
@@ -372,7 +400,7 @@ class Bucket
'%s://%s/%s.files/%s'
,
self
::
$streamWrapperProtocol
,
urlencode
(
$this
->
databaseName
),
urlencode
(
$this
->
options
[
'bucketName'
]
),
urlencode
(
$this
->
bucketName
),
urlencode
(
$id
)
);
}
...
...
@@ -388,7 +416,7 @@ class Bucket
'%s://%s/%s.files'
,
self
::
$streamWrapperProtocol
,
urlencode
(
$this
->
databaseName
),
urlencode
(
$this
->
options
[
'bucketName'
]
)
urlencode
(
$this
->
bucketName
)
);
}
...
...
@@ -399,7 +427,7 @@ class Bucket
*/
private
function
getFilesNamespace
()
{
return
sprintf
(
'%s.%s.files'
,
$this
->
databaseName
,
$this
->
options
[
'bucketName'
]
);
return
sprintf
(
'%s.%s.files'
,
$this
->
databaseName
,
$this
->
bucketName
);
}
/**
...
...
tests/GridFS/BucketFunctionalTest.php
View file @
1e3be59e
...
...
@@ -306,6 +306,18 @@ class BucketFunctionalTest extends FunctionalTestCase
$this
->
assertSameDocuments
(
$expected
,
$cursor
);
}
public
function
testGetBucketNameWithCustomValue
()
{
$bucket
=
new
Bucket
(
$this
->
manager
,
$this
->
getDatabaseName
(),
[
'bucketName'
=>
'custom_fs'
]);
$this
->
assertEquals
(
'custom_fs'
,
$bucket
->
getBucketName
());
}
public
function
testGetBucketNameWithDefaultValue
()
{
$this
->
assertEquals
(
'fs'
,
$this
->
bucket
->
getBucketName
());
}
public
function
testGetDatabaseName
()
{
$this
->
assertEquals
(
$this
->
getDatabaseName
(),
$this
->
bucket
->
getDatabaseName
());
...
...
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