Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger committed Feb 5, 2020
0 parents commit 067a4ee
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
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
10 changes: 10 additions & 0 deletions .gitattributes
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
/composer.lock
21 changes: 21 additions & 0 deletions LICENSE.md
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.
63 changes: 63 additions & 0 deletions README.md
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
29 changes: 29 additions & 0 deletions composer.json
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"
}
}
8 changes: 8 additions & 0 deletions examples/README.md
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).
19 changes: 19 additions & 0 deletions examples/init.php
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);
12 changes: 12 additions & 0 deletions examples/list.php
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;
}
15 changes: 15 additions & 0 deletions examples/read.php
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();
}


16 changes: 16 additions & 0 deletions examples/write.php
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);
14 changes: 14 additions & 0 deletions phpcs.xml
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>
38 changes: 38 additions & 0 deletions src/KDriveAdapter.php
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);
}
}

0 comments on commit 067a4ee

Please sign in to comment.