mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
move backends into their own namespace and add support for multiple auth methods
This commit is contained in:
parent
2280570d28
commit
29bdebad42
33 changed files with 752 additions and 377 deletions
71
src/Native/NativeServer.php
Normal file
71
src/Native/NativeServer.php
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
||||
* This file is licensed under the Licensed under the MIT license:
|
||||
* http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Icewind\SMB\Native;
|
||||
|
||||
use Icewind\SMB\AbstractServer;
|
||||
use Icewind\SMB\IAuth;
|
||||
use Icewind\SMB\System;
|
||||
use Icewind\SMB\TimeZoneProvider;
|
||||
|
||||
class NativeServer extends AbstractServer {
|
||||
/**
|
||||
* @var NativeState
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* @param string $host
|
||||
* @param IAuth $auth
|
||||
* @param System $system
|
||||
* @param TimeZoneProvider $timeZoneProvider
|
||||
*/
|
||||
public function __construct($host, IAuth $auth, System $system, TimeZoneProvider $timeZoneProvider) {
|
||||
parent::__construct($host, $auth, $system, $timeZoneProvider);
|
||||
$this->state = new NativeState();
|
||||
}
|
||||
|
||||
protected function connect() {
|
||||
$this->state->init($this->getAuth());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Icewind\SMB\IShare[]
|
||||
* @throws \Icewind\SMB\Exception\AuthenticationException
|
||||
* @throws \Icewind\SMB\Exception\InvalidHostException
|
||||
*/
|
||||
public function listShares() {
|
||||
$this->connect();
|
||||
$shares = array();
|
||||
$dh = $this->state->opendir('smb://' . $this->getHost());
|
||||
while ($share = $this->state->readdir($dh)) {
|
||||
if ($share['type'] === 'file share') {
|
||||
$shares[] = $this->getShare($share['name']);
|
||||
}
|
||||
}
|
||||
$this->state->closedir($dh);
|
||||
return $shares;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return \Icewind\SMB\IShare
|
||||
*/
|
||||
public function getShare($name) {
|
||||
return new NativeShare($this, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the smbclient php extension is available
|
||||
*
|
||||
* @param System $system
|
||||
* @return bool
|
||||
*/
|
||||
public static function available(System $system) {
|
||||
return function_exists('smbclient_state_new');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue