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
0b31800c
Commit
0b31800c
authored
Jan 11, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BucketReadWriter and GridFsStream are obsolete
parent
878896c7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
153 deletions
+0
-153
BucketReadWriter.php
src/GridFS/BucketReadWriter.php
+0
-125
GridFsStream.php
src/GridFS/GridFsStream.php
+0
-28
No files found.
src/GridFS/BucketReadWriter.php
deleted
100644 → 0
View file @
878896c7
<?php
namespace
MongoDB\GridFS
;
class
BucketReadWriter
{
private
$bucket
;
public
function
__construct
(
Bucket
$bucket
)
{
$this
->
bucket
=
$bucket
;
}
/**
* Opens a Stream for writing the contents of a file.
*
* @param string $filename file to upload
* @param array $options Stream Options
* @return Stream uploadStream
*/
public
function
openUploadStream
(
$filename
,
array
$options
=
[])
{
$options
=
[
'bucket'
=>
$this
->
bucket
,
'uploadOptions'
=>
$options
];
$context
=
stream_context_create
([
'gridfs'
=>
$options
]);
return
fopen
(
sprintf
(
'gridfs://%s/%s'
,
$this
->
bucket
->
getDatabaseName
(),
$filename
),
'w'
,
false
,
$context
);
}
/**
* Upload a file to this bucket by specifying the source stream file
*
* @param String $filename Filename To Insert
* @param Stream $source Source Stream
* @param array $options Stream Options
* @return ObjectId
*/
public
function
uploadFromStream
(
$filename
,
$source
,
array
$options
=
[])
{
$gridFsStream
=
new
GridFsUpload
(
$this
->
bucket
,
$filename
,
$options
);
return
$gridFsStream
->
uploadFromStream
(
$source
);
}
/**
* Opens a Stream for reading the contents of a file specified by ID.
*
* @param ObjectId $id
* @return Stream
*/
public
function
openDownloadStream
(
\MongoDB\BSON\ObjectId
$id
)
{
$options
=
[
'bucket'
=>
$this
->
bucket
];
$context
=
stream_context_create
([
'gridfs'
=>
$options
]);
return
fopen
(
sprintf
(
'gridfs://%s/%s'
,
$this
->
bucket
->
getDatabaseName
(),
$id
),
'r'
,
false
,
$context
);
}
/**
* Downloads the contents of the stored file specified by id and writes
* the contents to the destination Stream.
* @param ObjectId $id GridFS File Id
* @param Stream $destination Destination Stream
*/
public
function
downloadToStream
(
\MongoDB\BSON\ObjectId
$id
,
$destination
)
{
$gridFsStream
=
new
GridFsDownload
(
$this
->
bucket
,
$id
);
$gridFsStream
->
downloadToStream
(
$destination
);
}
/**
* Delete a file from the GridFS bucket. If the file collection entry is not found, still attempts to delete orphaned chunks
*
* @param ObjectId $id file id
* @throws GridFSFileNotFoundException
*/
public
function
delete
(
\MongoDB\BSON\ObjectId
$id
)
{
$options
=
[];
$writeConcern
=
$this
->
bucket
->
getWriteConcern
();
if
(
!
is_null
(
$writeConcern
))
{
$options
[
'writeConcern'
]
=
$writeConcern
;
}
$file
=
$this
->
bucket
->
getFilesCollection
()
->
findOne
([
'_id'
=>
$id
]);
$this
->
bucket
->
getChunksCollection
()
->
deleteMany
([
'files_id'
=>
$id
],
$options
);
if
(
is_null
(
$file
))
{
throw
new
\MongoDB\Exception\GridFSFileNotFoundException
(
$id
,
$this
->
bucket
->
getDatabaseName
(),
$this
->
bucket
->
getBucketName
());
}
$this
->
bucket
->
getFilesCollection
()
->
deleteOne
([
'_id'
=>
$id
],
$options
);
}
/**
* Open a stream to download a file from the GridFS bucket. Searches for the file by the specified name then returns a stream to the specified file
* @param string $filename name of the file to download
* @param int $revision the revision of the file to download
* @throws GridFSFileNotFoundException
*/
public
function
openDownloadStreamByName
(
$filename
,
$revision
=
-
1
)
{
$file
=
$this
->
bucket
->
findFileRevision
(
$filename
,
$revision
);
$options
=
[
'bucket'
=>
$this
->
bucket
,
'file'
=>
$file
];
$context
=
stream_context_create
([
'gridfs'
=>
$options
]);
return
fopen
(
sprintf
(
'gridfs://%s/%s'
,
$this
->
bucket
->
getDatabaseName
(),
$filename
),
'r'
,
false
,
$context
);
}
/**
* Download a file from the GridFS bucket by name. Searches for the file by the specified name then loads data into the stream
*
* @param string $filename name of the file to download
* @param int $revision the revision of the file to download
* @throws GridFSFileNotFoundException
*/
public
function
downloadToStreamByName
(
$filename
,
$destination
,
$revision
=-
1
)
{
$file
=
$this
->
bucket
->
findFileRevision
(
$filename
,
$revision
);
$gridFsStream
=
new
GridFsDownload
(
$this
->
bucket
,
null
,
$file
);
$gridFsStream
->
downloadToStream
(
$destination
);
}
/**
* Find files from the GridFS bucket files collection.
*
* @param array $filter filter to find by
* @param array $options options to
*/
public
function
find
(
$filter
,
array
$options
=
[])
{
return
$this
->
bucket
->
getFilesCollection
()
->
find
(
$filter
,
$options
);
}
}
src/GridFS/GridFsStream.php
deleted
100644 → 0
View file @
878896c7
<?php
namespace
MongoDB\GridFS
;
use
MongoDB\Collection
;
use
MongoDB\Exception\RuntimeException
;
/**
* GridFsStream holds the configuration for upload or download streams to GridFS
*
* @api
*/
class
GridFsStream
{
protected
$bucket
;
protected
$n
;
protected
$buffer
;
protected
$file
;
/**
* Constructs a GridFsStream
*
* @param \MongoDB\GridFS\Bucket $bucket GridFS Bucket
*/
public
function
__construct
(
Bucket
$bucket
)
{
$this
->
bucket
=
$bucket
;
$this
->
n
=
0
;
$this
->
buffer
=
fopen
(
'php://temp'
,
'w+'
);
}
}
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