move backends into their own namespace and add support for multiple auth methods

This commit is contained in:
Robin Appelman 2018-03-13 16:18:37 +01:00
commit 29bdebad42
33 changed files with 752 additions and 377 deletions

View file

@ -16,45 +16,50 @@ PHP wrapper for `smbclient` and [`libsmbclient-php`](https://github.com/eduardok
Examples
----
### Upload a file ###
### Connect to a share ###
```php
<?php
use Icewind\SMB\Server;
use Icewind\SMB\ServerFactory;
use Icewind\SMB\BasicAuth;
require('vendor/autoload.php');
$fileToUpload = __FILE__;
$serverFactory = new ServerFactory();
$auth = new BasicAuth('workgroup\test', 'test');
$server = $serverFactory->createServer('localhost', $auth);
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
```
The server factory will automatically pick between the `smbclient` and `libsmbclient-php`
based backend depending on what is available.
### Using kerberos authentication ###
```php
$serverFactory = new ServerFactory();
$auth = new KerberosAuth();
$server = $serverFactory->createServer('localhost', $auth);
```
Note that this requires a valid kerberos ticket to already be available for php
### Upload a file ###
```php
$share->put($fileToUpload, 'example.txt');
```
### Download a file ###
```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$target = __DIR__ . '/target.txt';
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$share->get('example.txt', $target);
```
### List shares on the remote server ###
```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$server = new Server('localhost', 'test', 'test');
$shares = $server->listShares();
foreach ($shares as $share) {
@ -65,13 +70,6 @@ foreach ($shares as $share) {
### List the content of a folder ###
```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$content = $share->dir('test');
foreach ($content as $info) {
@ -83,14 +81,6 @@ foreach ($content as $info) {
### Using read streams
```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$fh = $share->read('test.txt');
echo fread($fh, 4086);
fclose($fh);
@ -99,53 +89,14 @@ fclose($fh);
### Using write streams
```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$fh = $share->write('test.txt');
fwrite($fh, 'bar');
fclose($fh);
```
### Using libsmbclient-php ###
Install [libsmbclient-php](https://github.com/eduardok/libsmbclient-php)
```php
<?php
use Icewind\SMB\Server;
use Icewind\SMB\NativeServer;
require('vendor/autoload.php');
$fileToUpload = __FILE__;
if (Server::NativeAvailable()) {
$server = new NativeServer('localhost', 'test', 'test');
} else {
echo 'libsmbclient-php not available, falling back to wrapping smbclient';
$server = new Server('localhost', 'test', 'test');
}
$share = $server->getShare('test');
$share->put($fileToUpload, 'example.txt');
```
### Using notify
```php
<?php
use Icewind\SMB\Server;
require('vendor/autoload.php');
$server = new Server('localhost', 'test', 'test');
$share = $server->getShare('test');
$share->notify('')->listen(function (\Icewind\SMB\Change $change) {
echo $change->getCode() . ': ' . $change->getPath() . "\n";
});