BrowserConnector
BrowserConnector
Coordinates browser-style file operations across one or more storage managers.
class BrowserConnectorThis connector translates browser target tokens into manager/path references, normalises output payloads for front-end consumers, and exposes higher-level actions such as browse, tree traversal, upload, move, copy, metadata updates, and remote URL ingestion.
Properties
sources
Registered file sources keyed by source identifier.
private array $sourcesurl
Base URL used when building file links and preview URLs.
private string $urlallowPreview
List of MIME match expressions allowed for in-browser previews.
private array $allowPreviewExpressions are passed to {@see Str::pregMatchArray()}.
public $Methods
__construct
Creates a new browser connector instance.
public __construct(?string $url, ?array $allowPreview): voidParameters
| Parameter | Type | Description |
|---|---|---|
$url | string | base URL used to build public links and preview URLs |
$allowPreview | array | MIME patterns that can be previewed in the UI |
setProgressCallback
Sets a progress callback for long-running connector actions.
public setProgressCallback(\Closure $callback): voidParameters
| Parameter | Type | Description |
|---|---|---|
$callback | \Closure | receives operation-specific progress updates |
addSource
Adds a browsable source by manager instance or filesystem path.
public addSource(string $id, string $source, ?string $name): boolWhen a string path is provided, a local manager is created automatically.
Parameters
| Parameter | Type | Description |
|---|---|---|
$id | string | source key used in encoded target tokens |
$source | string | existing manager instance or local root path |
$name | string | optional display name shown by browser clients |
authorised
Returns true when all sources are authorised, otherwise the failing source ID.
public authorised(): stringauthorise
Initiates authorisation flow for a source.
public authorise(string $sourceName, ?string $redirectUri): boolParameters
| Parameter | Type | Description |
|---|---|---|
$sourceName | string | source identifier registered with {@see addSource()} |
$redirectUri | string | optional callback URL used by providers that require redirect flows |
source
Resolves a target token to its source manager.
public source(string $target): ManagerParameters
| Parameter | Type | Description |
|---|---|---|
$target | string | encoded source token or raw source identifier |
path
Resolves a target token to its internal path.
public path(string $target): stringParameters
| Parameter | Type | Description |
|---|---|---|
$target | string | encoded source/path token |
info
Builds a browser-facing metadata payload for a file system entry.
public info(Manager $source, File $file): voidThe result is suitable for responses consumed by file browser front ends.
Parameters
| Parameter | Type | Description |
|---|---|---|
$source | Manager | manager that owns the entry |
$file | File | file or directory to describe |
tree
Produces a flattened directory tree response.
public tree(?string $target, ?int $depth, false $): voidWithout a target, the method returns root entries for all configured sources. With a target, it traverses directories under that target up to the specified depth.
Parameters
| Parameter | Type | Description |
|---|---|---|
$target | string | encoded directory target to traverse, or null for source roots |
$depth | int | maximum recursion depth; null for unlimited |
$ | false |
open
Opens a directory target and returns current working directory details and children.
public open(string $target, bool $tree, int $depth = 1, ?string $filter, bool $withMeta, false $): voidParameters
| Parameter | Type | Description |
|---|---|---|
$target | string | encoded directory target |
$tree | bool | when true, include a directory tree payload |
$depth | int | tree recursion depth when $tree is enabled |
$filter | string | optional regex pattern used to filter by MIME type |
$withMeta | bool | include metadata per file entry |
$ | false |
get
Returns a downloadable file response for a browser target.
public get(string $target): FileResponseParameters
| Parameter | Type | Description |
|---|---|---|
$target | string | encoded file target |
getFile
Returns a file from a source and path.
public getFile(string $source, string $path = '/'): FileParameters
| Parameter | Type | Description |
|---|---|---|
$source | string | source identifier or encoded target |
$path | string | internal path relative to the source root |
getFileByPath
Returns a file from a {source}/{path} string.
public getFileByPath(string $path): FileParameters
| Parameter | Type | Description |
|---|---|---|
$path | string | combined source/path representation |
mkdir
Creates a directory inside the provided parent target.
public mkdir(string $parent, string $name): voidParameters
| Parameter | Type | Description |
|---|---|---|
$parent | string | encoded parent directory target |
$name | string | name of the child directory to create |
rmdir
Removes a directory target.
public rmdir(string $target, bool $recurse): voidParameters
| Parameter | Type | Description |
|---|---|---|
$target | string | encoded directory target |
$recurse | bool | whether to remove child items recursively |
unlink
Deletes one or more files.
public unlink(string $target): voidParameters
| Parameter | Type | Description |
|---|---|---|
$target | string |
copy
Copies a file or directory from one target to another.
public copy(string $from, string $to): voidSupports cross-source copy when managers support it and may emit progress notifications through the configured callback.
Parameters
| Parameter | Type | Description |
|---|---|---|
$from | string | encoded source target |
$to | string | encoded destination directory target |
move
Moves a file or directory from one target to another.
public move(string $from, string $to, false $): voidParameters
| Parameter | Type | Description |
|---|---|---|
$from | string | encoded source target |
$to | string | encoded destination directory target |
$ | false |
rename
Renames a file or directory.
public rename(string $target, string $name, bool $withMeta): voidParameters
| Parameter | Type | Description |
|---|---|---|
$target | string | encoded target to rename |
$name | string | new basename to assign |
$withMeta | bool | include metadata in the response payload |
upload
Uploads a single file payload into the target directory.
public upload(string $parent, array $file, ?string $relativePath, false $): voidWhen $relativePath is provided, missing intermediate directories are created.
Parameters
| Parameter | Type | Description |
|---|---|---|
$parent | string | encoded destination directory target |
$file | array | uploaded file payload (for example $_FILES item) |
$relativePath | string | optional relative path from browser directory uploads |
$ | false |
getMeta
Retrieves metadata associated with a file or directory target.
public getMeta(string $target, ?string $key): voidParameters
| Parameter | Type | Description |
|---|---|---|
$target | string | encoded file or directory target |
$key | string | specific metadata key, or null for all metadata |
setMeta
Writes metadata values to a file or directory target.
public setMeta(string $target, array $values): voidParameters
| Parameter | Type | Description |
|---|---|---|
$target | string | encoded file or directory target |
$values | array | metadata values to persist |
snatch
Downloads a remote URL and stores it in the target directory.
public snatch(string $url, string $target): voidParameters
| Parameter | Type | Description |
|---|---|---|
$url | string | remote resource URL |
$target | string | encoded destination directory target |
search
Searches for entries under a target path and returns browser metadata rows.
public search(string $target, string $query): voidParameters
| Parameter | Type | Description |
|---|---|---|
$target | string | encoded target path used as the search root |
$query | string | search expression passed to the backing manager |
target
Encodes a source/path pair to a browser target token.
private target(string $source, ?string $path): stringParameters
| Parameter | Type | Description |
|---|---|---|
$source | string | manager instance or source identifier |
$path | string | optional path component to encode |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000