Skip to content

Commit 670430b

Browse files
committed
Merge branch 'master' of github.com:thephpleague/flysystem
2 parents 7fe2668 + 868cbf7 commit 670430b

File tree

3 files changed

+245
-0
lines changed

3 files changed

+245
-0
lines changed

docs/adapter/phpcr.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ composer require jackalope/jackalope-doctrine-dbal league/flysystem-phpcr
2424
Bootstrap your PHPCR implementation. If you chose jackalope-doctrine-dbal with sqlite,
2525
this will look like this for example:
2626

27+
<<<<<<< HEAD
2728
```php
2829
use Doctrine\DBAL\Driver\Connection;
2930
use Doctrine\DBAL\DriverManager;

docs/api.md

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
---
2+
layout: default
3+
permalink: /api/
4+
title: API
5+
---
6+
7+
# API
8+
9+
## General Usage
10+
11+
__Write Files__
12+
13+
~~~ php
14+
$filesystem->write('path/to/file.txt', 'contents');
15+
~~~
16+
17+
__Update Files__
18+
19+
~~~ php
20+
$filesystem->update('path/to/file.txt', 'new contents');
21+
~~~
22+
23+
__Write or Update Files__
24+
25+
~~~ php
26+
$filesystem->put('path/to/file.txt', 'contents');
27+
~~~
28+
29+
__Read Files__
30+
31+
~~~ php
32+
$contents = $filesystem->read('path/to/file.txt');
33+
~~~
34+
35+
__Check if a file exists__
36+
37+
~~~ php
38+
$exists = $filesystem->has('path/to/file.txt');
39+
~~~
40+
41+
__NOTE__: This only has consistent behaviour for files, not directories. Directories
42+
are less important in Flysystem, they're created implicitly and often ignored because
43+
not every adapter (filesystem type) supports directories.
44+
45+
__Delete Files__
46+
47+
~~~ php
48+
$filesystem->delete('path/to/file.txt');
49+
~~~
50+
51+
__Read and Delete__
52+
53+
~~~ php
54+
$contents = $filesystem->readAndDelete('path/to/file.txt');
55+
~~~
56+
57+
__Rename Files__
58+
59+
~~~ php
60+
$filesystem->rename('filename.txt', 'newname.txt');
61+
~~~
62+
63+
__Copy Files__
64+
65+
~~~ php
66+
$filesystem->copy('filename.txt', 'duplicate.txt');
67+
~~~
68+
69+
__Get Mimetypes__
70+
71+
~~~ php
72+
$mimetype = $filesystem->getMimetype('path/to/file.txt');
73+
~~~
74+
75+
__Get Timestamps__
76+
77+
~~~ php
78+
$timestamp = $filesystem->getTimestamp('path/to/file.txt');
79+
~~~
80+
81+
__Get File Sizes__
82+
83+
~~~ php
84+
$size = $filesystem->getSize('path/to/file.txt');
85+
~~~
86+
87+
__Create Directories__
88+
89+
~~~ php
90+
$filesystem->createDir('path/to/nested/directory');
91+
~~~
92+
Directories are also made implicitly when writing to a deeper path
93+
94+
~~~ php
95+
$filesystem->write('path/to/file.txt', 'contents');
96+
~~~
97+
98+
__Delete Directories__
99+
100+
~~~ php
101+
$filesystem->deleteDir('path/to/directory');
102+
~~~
103+
The above method will delete directories recursively
104+
105+
__NOTE__: All paths used by Flysystem API are relative to the adapter root directory.
106+
107+
__Manage Visibility__
108+
109+
Visibility is the abstraction of file permissions across multiple platforms. Visibility can be either public or private.
110+
111+
~~~ php
112+
use League\Flysystem\AdapterInterface;
113+
114+
$filesystem->write('db.backup', $backup, [
115+
'visibility' => AdapterInterface::VISIBILITY_PRIVATE
116+
]);
117+
118+
// or simply
119+
120+
$filesystem->write('db.backup', $backup, ['visibility' => 'private']);
121+
~~~
122+
123+
You can also change and check visibility of existing files
124+
125+
~~~ php
126+
if ($filesystem->getVisibility('secret.txt') === 'private') {
127+
$filesystem->setVisibility('secret.txt', 'public');
128+
}
129+
~~~
130+
131+
## Global visibility setting
132+
133+
You can set the visibility as a default, which prevents you from setting it all over the place.
134+
135+
~~~ php
136+
$filesystem = new League\Flysystem\Filesystem($adapter, [
137+
'visibility' => AdapterInterface::VISIBILITY_PRIVATE
138+
]);
139+
~~~
140+
141+
__List Contents__
142+
143+
~~~ php
144+
$contents = $filesystem->listContents();
145+
~~~
146+
147+
The result of a contents listing is a collection of arrays containing all the metadata the file manager knows at that time. By default you'll receive path info and file type. Additional info could be supplied by default depending on the adapter used.
148+
149+
Example:
150+
151+
~~~ php
152+
foreach ($contents as $object) {
153+
echo $object['basename'].' is located at '.$object['path'].' and is a '.$object['type'];
154+
}
155+
~~~
156+
157+
By default Flysystem lists the top directory non-recursively. You can supply a directory name and recursive boolean to get more precise results
158+
159+
~~~ php
160+
$contents = $filesystem->listContents('some/dir', true);
161+
~~~
162+
163+
__List paths__
164+
165+
~~~ php
166+
$filesystem->addPlugin(new ListPaths());
167+
168+
$paths = $filesystem->listPaths();
169+
170+
foreach ($paths as $path) {
171+
echo $path;
172+
}
173+
~~~
174+
175+
__List with ensured presence of specific metadata__
176+
177+
~~~ php
178+
$listing = $filesystem->listWith(['mimetype', 'size', 'timestamp'], 'optional/path/to/dir', true);
179+
180+
foreach ($listing as $object) {
181+
echo $object['path'].' has mimetype: '.$object['mimetype'];
182+
}
183+
~~~
184+
185+
__Get file into with explicit metadata__
186+
187+
~~~ php
188+
$info = $filesystem->getWithMetadata('path/to/file.txt', ['timestamp', 'mimetype']);
189+
echo $info['mimetype'];
190+
echo $info['timestamp'];
191+
~~~
192+
193+
__NOTE__: This requires the `League\Flysystem\Plugin\GetWithMetadata` plugin.
194+
195+
## Using streams for reads and writes
196+
197+
<p class="message-notice">
198+
Some SDK's close streams after consuming them, therefore, before calling fclose on the resource, check if it's still valid using <code>is_resource</code>.
199+
</p>
200+
201+
~~~ php
202+
$stream = fopen('/path/to/database.backup', 'r+');
203+
$filesystem->writeStream('backups/'.strftime('%G-%m-%d').'.backup', $stream);
204+
205+
// Using write you can also directly set the visibility
206+
$filesystem->writeStream('backups/'.strftime('%G-%m-%d').'.backup', $stream, [
207+
'visibility' => AdapterInterface::VISIBILITY_PRIVATE
208+
]);
209+
210+
if (is_resource($stream)) {
211+
fclose($stream);
212+
}
213+
214+
// Or update a file with stream contents
215+
$filesystem->updateStream('backups/'.strftime('%G-%m-%d').'.backup', $stream);
216+
217+
// Retrieve a read-stream
218+
$stream = $filesystem->readStream('something/is/here.ext');
219+
$contents = stream_get_contents($stream);
220+
fclose($stream);
221+
222+
// Create or overwrite using a stream.
223+
$putStream = tmpfile();
224+
fwrite($putStream, $contents);
225+
rewind($putStream);
226+
$filesystem->putStream('somewhere/here.txt', $putStream);
227+
228+
if (is_resource($putStream)) {
229+
fclose($putStream);
230+
}
231+
~~~

src/Util/MimeType.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public static function getExtensionToMimeTypeMap()
165165
'movie' => 'video/x-sgi-movie',
166166
'doc' => 'application/msword',
167167
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
168+
'docm' => 'application/vnd.ms-word.template.macroEnabled.12',
168169
'dot' => 'application/msword',
169170
'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
170171
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
@@ -214,6 +215,18 @@ public static function getExtensionToMimeTypeMap()
214215
'cdr' => 'application/cdr',
215216
'wma' => 'audio/x-ms-wma',
216217
'jar' => 'application/java-archive',
218+
'tex' => 'application/x-tex',
219+
'latex' => 'application/x-latex',
220+
'odt' => 'application/vnd.oasis.opendocument.text',
221+
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
222+
'odp' => 'application/vnd.oasis.opendocument.presentation',
223+
'odg' => 'application/vnd.oasis.opendocument.graphics',
224+
'odc' => 'application/vnd.oasis.opendocument.chart',
225+
'odf' => 'application/vnd.oasis.opendocument.formula',
226+
'odi' => 'application/vnd.oasis.opendocument.image',
227+
'odm' => 'application/vnd.oasis.opendocument.text-master',
228+
'odb' => 'application/vnd.oasis.opendocument.database',
229+
'ott' => 'application/vnd.oasis.opendocument.text-template',
217230
];
218231
}
219232
}

0 commit comments

Comments
 (0)