This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 067a4ee
Showing
13 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at https://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Path-based git attributes | ||
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html | ||
|
||
# Ignore all unnecessary files with "export-ignore". | ||
/.editoconfig export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/examples export-ignore | ||
/phpcs.xml export-ignore | ||
/README.md export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor/ | ||
/composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) 2020 Nicolas Hedger <[email protected]> | ||
|
||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
> in the Software without restriction, including without limitation the rights | ||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
> copies of the Software, and to permit persons to whom the Software is | ||
> furnished to do so, subject to the following conditions: | ||
> | ||
> The above copyright notice and this permission notice shall be included in | ||
> all copies or substantial portions of the Software. | ||
> | ||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
> THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Flysystem adapter for Infomaniak kDrive | ||
|
||
[![Latest Version on Packagist][icon-version]][link-packagist] | ||
[![Software License][icon-license]](LICENSE.md) | ||
[![Total Downloads][icon-license]][link-packagist] | ||
|
||
This package contains a [Flysystem](https://flysystem.thephpleague.com/) adapter for [Infomaniak kDrive](https://www.infomaniak.com/en/kdrive/). It is built on top of the Flysystem [WebDAV adapter](https://github.com/thephpleague/flysystem-webdav). | ||
|
||
## Installation | ||
Via [Composer](https://getcomposer.org/) | ||
```shell script | ||
composer require infomaniak/flysystem-kdrive | ||
``` | ||
|
||
## Credentials | ||
To be able to connect to your kDrive, you'll need the following information. | ||
|
||
1. Your kDrive ID ([Find your kDrive ID](#find-your-kdrive-id)) | ||
2. Your login email address (the one you'd use on https://manager.infomaniak.com) | ||
3. A unique application password ([Generate an application password](https://manager.infomaniak.com/v3/profile/application-password)) | ||
|
||
### Find your kDrive ID | ||
1. Connect to your kDrive directly on Infomaniak | ||
2. Find your drive's ID in the URL : `https://drive.infomaniak.com/app/drive/[ID]/files` | ||
|
||
## Usage | ||
|
||
```php | ||
use Infomaniak\KDrive\KDriveAdapter; | ||
use League\Flysystem\Filesystem; | ||
|
||
$kDrive = new KDriveAdapter( | ||
'123456', // Your kDrive's ID | ||
'[email protected]', // Your Infomaniak login email address | ||
'********************', // Your generated password | ||
); | ||
|
||
$filesystem = new Filesystem($kDrive); | ||
``` | ||
|
||
### Path prefix | ||
If you wish to use a specific folder on your drive as your storage root, initialize the adapter with a custom | ||
path prefix. | ||
|
||
```php | ||
$kDrive = new KDriveAdapter( | ||
'123456', // Your kDrive's ID | ||
'[email protected]', // Your Infomaniak login email address | ||
'********************', // Your generated password | ||
'my/custom/path' // A custom path prefix | ||
); | ||
``` | ||
|
||
## Examples | ||
Go to the [examples](examples) directory to find a few examples to get you started. | ||
|
||
## License | ||
The MIT License (MIT). Please see the [LICENSE](LICENSE.md) for more information. | ||
|
||
[icon-version]: https://img.shields.io/packagist/v/infomaniak/flysystem-kdrive?style=flat-square | ||
[icon-license]: https://img.shields.io/packagist/l/infomaniak/flysystem-kdrive?style=flat-square | ||
[icon-downloads]: https://img.shields.io/packagist/dt/infomaniak/flysystem-kdrive?style=flat-square | ||
[link-packagist]: https://packagist.org/packages/infomaniak/flysystem-kdrive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "infomaniak/flysystem-kdrive", | ||
"description": "Flysystem Adapter for Infomaniak kDrive", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Nicolas Hedger", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Infomaniak\\KDrive\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "stable", | ||
"require": { | ||
"ext-curl": "*", | ||
"league/flysystem-webdav": "^1.0" | ||
}, | ||
"require-dev": { | ||
"squizlabs/php_codesniffer": "^3.5" | ||
}, | ||
"scripts": { | ||
"check-style": "phpcs src", | ||
"fix-style": "phpcbf src" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Examples | ||
|
||
You'll find a few examples to get you started in this directory. | ||
|
||
## Setup | ||
|
||
Install all the dependencies by running `composer install` at the root of this repository | ||
and setup your credentials in the [init.php](init.php). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* This is not an example file. It is included in the examples files | ||
* in this folder to setup the environment. | ||
*/ | ||
|
||
require dirname(__DIR__). '/vendor/autoload.php'; | ||
|
||
use Infomaniak\KDrive\KDriveAdapter; | ||
use League\Flysystem\Filesystem; | ||
|
||
$kDrive = new KDriveAdapter( | ||
'123456', | ||
'[email protected]', | ||
'********************' | ||
); | ||
|
||
$filesystem = new Filesystem($kDrive); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
// Initial setup | ||
require 'init.php'; | ||
|
||
// Get the list of files in the given folder | ||
$files = $filesystem->listContents('./', $recursive = false); | ||
|
||
// Print the list of files | ||
foreach ($files as $file) { | ||
echo $file['type'] . ' - ' . $file['path'] . PHP_EOL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
use League\Flysystem\FileNotFoundException; | ||
|
||
// Initial setup | ||
require 'init.php'; | ||
|
||
// Try reading a file | ||
try { | ||
echo $filesystem->read('lorem ipsum.txt'); | ||
} catch (FileNotFoundException $e) { | ||
echo $e->getMessage(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
// Initial setup | ||
require 'init.php'; | ||
|
||
$data = <<<EOF | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut id turpis sed leo | ||
accumsan mattis. Nulla et dui eget dolor varius mollis sed in est. Sed et mollis | ||
massa. Aliquam erat volutpat. Ut efficitur auctor libero, sed fermentum enim | ||
bibendum at. Morbi ipsum risus, pharetra id diam sit amet, tempus finibus sem. | ||
Duis placerat sem sit amet enim sagittis consectetur. In hac habitasse platea | ||
dictumst. Curabitur in laoreet turpis. | ||
EOF; | ||
|
||
// Write the data to the file | ||
$filesystem->put('lorem ipsum.txt', $data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="infomaniak/flysystem-kdrive"> | ||
<description>The coding standard of infomaniak/flysystem-kdrive package</description> | ||
<arg value="p" /> | ||
|
||
<config name="ignore_warnings_on_exit" value="1" /> | ||
<config name="ignore_errors_on_exit" value="1" /> | ||
|
||
<arg name="colors" /> | ||
<arg value="s" /> | ||
|
||
<!-- Use the PSR2 Standard--> | ||
<rule ref="PSR2" /> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Infomaniak\KDrive; | ||
|
||
use League\Flysystem\WebDAV\WebDAVAdapter; | ||
use Sabre\DAV\Client; | ||
|
||
class KDriveAdapter extends WebDAVAdapter | ||
{ | ||
/** | ||
* KDriveAdapter | ||
* | ||
* Initializes a new kDrive Adapter | ||
* | ||
* @param string $kDriveId Id of your drive, as found on Infomaniak | ||
* @param string $username Infomaniak login email address | ||
* @param string $password Application password, as generated on Infomaniak | ||
* @param null|string $prefix Optional path prefix on the drive | ||
* @param bool $useStreamedCopy | ||
*/ | ||
public function __construct( | ||
$kDriveId, | ||
$username, | ||
$password, | ||
$prefix = null, | ||
$useStreamedCopy = true | ||
) { | ||
$settings = [ | ||
'baseUri' => "https://${kDriveId}.connect.drive.infomaniak.com", | ||
'userName' => $username, | ||
'password' => $password | ||
]; | ||
|
||
$client = new Client($settings); | ||
|
||
parent::__construct($client, $prefix, $useStreamedCopy); | ||
} | ||
} |