SMBBase2
abstract class SMBBase2 extends SMBBase1
Traits
Trait for storage classes that store a possibly-encrypted username and password
Trait for storage classes that store a optionally-encrypted credential fields
Trait allowing objects to store fields encrypted with an account's crypto
A storage that has a base path
Constants
| IDLength |
The length of the ID used to identify the object |
Properties
| protected | $database | The object's primary reference to the database |
from BaseObject |
| protected Scalar> | $scalars | from BaseObject | |
| protected ObjectRef> | $objects | from BaseObject | |
| protected ObjectRefs> | $objectrefs | from BaseObject | |
| private | $modified | whether or not this object has been modified |
from BaseObject |
| private | $deleted | whether or not this object has been deleted |
from BaseObject |
| private | $dbDeleted | whether or not this object has been deleted by DB |
from BaseObject |
| private | $deleteLater | from BaseObject | |
| private | $created | True if this object has been created and not yet saved to DB |
from BaseObject |
| static private | $instances | array of all instantiated storages |
from Storage |
| protected | $createdItems | array of paths that were newly created |
from Storage |
| protected | $onRollback | array of functions to run for rollback |
from Storage |
| private | $contexts | array<path, FileContext> map for all file handles |
from FWrapper |
| private | $crypto_cache | Stores fields decrypted in memory |
from FieldCrypt |
Methods
Returns the name of the class that should be used in the database for the table name (cast down at save)
Counts objects in the DB matching the given query
Loads an array of objects from the DB matching the given query
Deletes objects from the DB matching the given query
Loads a unique object matching the given query
Loads all objects of this type from the database
Loads objects from the database with the given object ID as the value of the given field
Deletes objects from the database with the given object ID as the value of the given field
Loads a unique object matching the given field
Deletes a unique object matching the given field
Loads objects from the database with the given object referenced by the given field
Deletes objects from the database with the given object referenced by the given field
Loads a unique object from the database with the given object referenced by the given field
Deletes a unique object from the database with the given object referenced by the given field
Returns the string "id:class" where id is the object ID and class is its short class name
Same as GetScalar() but returns null instead of throwing exceptions
Returns the delta of the given scalar (non-zero if modified)
Same as GetObject() but returns null instead of throwing exceptions
Checks if the object reference is not-null without actually loading it (faster)
Gets the ID of a referenced object without actually loading it (faster)
Same as GetObjectID() but returns null instead of throwing exceptions
Gets the class name of a referenced object without actually loading it (faster)
Gets the class name of a referenced object without actually loading it (faster)
Gets an array of objects that reference this object
Gets the counter of objects referencing this object
Loads the object that joins together two classes using a FieldTypes\ObjectJoin
Same as GetJoinObject() but returns null instead of throwing exceptions
Deletes all objects that reference this object
Sets a scalar field to the given value
Increment a counter by the given value
Sets a field to reference the given object
Same as BoolSetObject() but returns $this
Adds an object reference, checking for a limit on the number of references
Removes the given object from a collection of referenced objects
Constructs the object by initializing its field template with values from the database
Function to allow subclasses to do something after being constructed without overriding the constructor
Collects fields that have changed and saves them to the database
whether or not this object has been, or should be considered, deleted
True if this object has been created and not yet saved to DB (should not be overriden)
Returns the timestamp value stored in the given date field
Returns the timestamp value stored in the given date field
Sets the value of the given date field to the given value
Gets the value of the given feature field as an int (used for config)
Gets the value of the given feature field as an int (used for config)
Gets the value of the given feature field as a bool (used for config)
Gets the value of the given feature field as a bool (used for config)
Sets the value of the given feature field to the given (?int) value
Sets the value of the given feature field to the given (?bool) value
Returns true if the given feature has been modified
Gets the value of the given counter limit field
Gets the value of the given counter limit field
Sets the value of the given counter limit field
Checks whether the given counter plus a delta would exceed the limit
Gets an array of the values of all fields matching a prefix
Returns all objects owned by the given account
Imports an existing file into the storage
The storage-specific ImportFile
The storage-specific ReadBytes
The storage-specific WriteBytes
Deletes the empty folder with the given path - NO ROLLBACK
Renames a file from $old to $new - path shall not change
Renames a folder from $old to $new - path shall not change
Moves a file from $old to $new - name shall not change
Moves a folder from $old to $new - name shall not change
Copies a file from $old to $new (path and name can change)
Copies a folder from $old to $new (path and name can change)
Moves all pending rollback actions from $old to $new for delete tracking
Deletes all pending rollback actions for the given path
Returns true if we can read from a stream opened as write
Returns true if an already-open stream can be seeked randomly
Returns a new handle for the given path
Returns a context for the given file
Returns the full storage level path for the given root-relative path
Returns the list of fields encrypted in this object
Gets the extra DB fields required for this trait
Decrypts and returns the value of the given field
Decrypts and returns the value of the given field
Sets the value of the given field
Loads any objects for the given account and decrypts their fields
Returns the printable client object of this trait
Details
in
BasePath at line 119
static array
GetFieldTemplate()
No description
in
BaseObject at line 52
static string
GetDBClass()
Returns the name of the class that should be used in the database for the table name (cast down at save)
Defaults to the actual class used. Can be overriden e.g. if multiple classes need to use the same table.
in
BaseObject at line 60
static string
GetObjClass(array $row)
No description
in
BaseObject at line 68
static int
CountByQuery(ObjectDatabase $database, QueryBuilder $query)
Counts objects in the DB matching the given query
in
BaseObject at line 79
static array
LoadByQuery(ObjectDatabase $database, QueryBuilder $query)
Loads an array of objects from the DB matching the given query
in
BaseObject at line 92
static int
DeleteByQuery(ObjectDatabase $database, QueryBuilder $query)
Deletes objects from the DB matching the given query
The objects are loaded when they are deleted and their Delete()s are run
in
BaseObject at line 103
static BaseObject|null
TryLoadUniqueByQuery(ObjectDatabase $database, QueryBuilder $query)
Loads a unique object matching the given query
in
BaseObject at line 116
static BaseObject
NotNull(BaseObject|null $obj)
Asserts that the given object is not null
in
BaseObject at line 127
static BaseObject|null
TryLoadByID(ObjectDatabase $database, string $id)
Loads a unique object by its ID
in
BaseObject at line 137
static void
DeleteByID(ObjectDatabase $database, string $id)
Deletes a unique object by its ID
in
BaseObject at line 150
static array
LoadAll(ObjectDatabase $database, int|null $limit = null, int|null $offset = null)
Loads all objects of this type from the database
in
BaseObject at line 160
static int
DeleteAll(ObjectDatabase $database)
Deletes all objects of this type from the database
in
BaseObject at line 176
static array
LoadByObjectID(ObjectDatabase $database, string $field, string $id, string|null $class = null)
Loads objects from the database with the given object ID as the value of the given field
Can be used as an alternative to LoadByObject() to avoid actually loading the object
in
BaseObject at line 193
static int
DeleteByObjectID(ObjectDatabase $database, string $field, string $id, string|null $class = null)
Deletes objects from the database with the given object ID as the value of the given field
Can be used as an alternative to DeleteByObject() to avoid actually loading the object
in
BaseObject at line 206
static protected BaseObject|null
TryLoadUniqueByKey(ObjectDatabase $database, string $field, string $key)
Loads a unique object matching the given field
in
BaseObject at line 218
static protected bool
TryDeleteByUniqueKey(ObjectDatabase $database, string $field, string $key)
Deletes a unique object matching the given field
in
BaseObject at line 233
static array
LoadByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)
Loads objects from the database with the given object referenced by the given field
in
BaseObject at line 247
static int
DeleteByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)
Deletes objects from the database with the given object referenced by the given field
in
BaseObject at line 261
static BaseObject|null
TryLoadUniqueByObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)
Loads a unique object from the database with the given object referenced by the given field
in
BaseObject at line 275
static bool
TryDeleteByUniqueObject(ObjectDatabase $database, string $field, BaseObject $object, bool $isPoly = false)
Deletes a unique object from the database with the given object referenced by the given field
in
BaseObject at line 284
string
ID()
Returns the unique ID of the object
in
BaseObject at line 287
string
__toString()
Returns the string "id:class" where id is the object ID and class is its short class name
in
BaseObject at line 290
static string|null
toString(BaseObject|null $obj)
Returns the given object's as a string if not null, else null
in
BaseObject at line 309
protected mixed
GetScalar(string $field, bool $allowTemp = true)
Gets a scalar field
in
BaseObject at line 322
protected
TryGetScalar(string $field, bool $allowTemp = true)
Same as GetScalar() but returns null instead of throwing exceptions
in
BaseObject at line 336
protected int
GetScalarDelta(string $field)
Returns the delta of the given scalar (non-zero if modified)
in
BaseObject at line 351
protected BaseObject
GetObject(string $field)
Gets a single object reference
in
BaseObject at line 365
protected BaseObject|null
TryGetObject(string $field)
Same as GetObject() but returns null instead of throwing exceptions
in
BaseObject at line 379
protected bool
HasObject(string $field)
Checks if the object reference is not-null without actually loading it (faster)
in
BaseObject at line 394
protected string
GetObjectID(string $field)
Gets the ID of a referenced object without actually loading it (faster)
in
BaseObject at line 408
protected string|null
TryGetObjectID(string $field)
Same as GetObjectID() but returns null instead of throwing exceptions
in
BaseObject at line 422
protected string
GetObjectType(string $field)
Gets the class name of a referenced object without actually loading it (faster)
in
BaseObject at line 438
protected string|null
TryGetObjectType(string $field)
Gets the class name of a referenced object without actually loading it (faster)
in
BaseObject at line 451
protected BaseObject
DeleteObject(string $field)
Deletes the object referenced in the field
in
BaseObject at line 467
protected array
GetObjectRefs(string $field, int|null $limit = null, int|null $offset = null)
Gets an array of objects that reference this object
in
BaseObject at line 481
protected int
CountObjectRefs(string $field)
Gets the counter of objects referencing this object
in
BaseObject at line 497
protected StandardObject
GetJoinObject(string $field, BaseObject $obj)
Loads the object that joins together two classes using a FieldTypes\ObjectJoin
in
BaseObject at line 514
protected StandardObject|null
TryGetJoinObject(string $field, BaseObject $obj)
Same as GetJoinObject() but returns null instead of throwing exceptions
in
BaseObject at line 530
protected BaseObject
DeleteObjects(string $field)
Deletes all objects that reference this object
in
BaseObject at line 546
protected BaseObject
SetScalar(string $field, mixed $value, bool $temp = false)
Sets a scalar field to the given value
in
StandardObject at line 173
protected BaseObject
DeltaCounter(string $name, int $delta = 1, bool $ignoreLimit = false)
Increment a counter by the given value
in
BaseObject at line 598
protected bool
BoolSetObject(string $field, BaseObject|null $object, bool $notification = false)
Sets a field to reference the given object
Will also call SetObject or AddObjectRef on the given object as appropriate for two-way references
in
BaseObject at line 649
protected BaseObject
SetObject(string $field, BaseObject|null $object, bool $notification = false)
Same as BoolSetObject() but returns $this
in
StandardObject at line 185
protected bool
AddObjectRef(string $field, BaseObject $object, bool $notification = false)
Adds an object reference, checking for a limit on the number of references
in
BaseObject at line 696
protected bool
RemoveObjectRef(string $field, BaseObject $object, bool $notification = false)
Removes the given object from a collection of referenced objects
in
BaseObject at line 727
__construct(ObjectDatabase $database, array $data)
Constructs the object by initializing its field template with values from the database
in
BaseObject at line 750
private
AddField(string $key, Scalar $field)
Adds the given field object to the correct internal array
in
Storage at line 651
void
SubConstruct()
Function to allow subclasses to do something after being constructed without overriding the constructor
in
BaseObject at line 771
BaseObject
Save(bool $onlyMandatory = false)
Collects fields that have changed and saves them to the database
in
BaseObject at line 814
bool
isDeleted()
whether or not this object has been, or should be considered, deleted
This function can be overriden with a custom validity-check, and is used as a filter when loading objects
in
BaseObject at line 820
void
NotifyDBDeleted()
Deletes this object without sending to the DB
in
BaseObject at line 823
void
Delete()
Deletes this object from the DB
in
BaseObject at line 849
protected void
DeleteLater()
Schedules the object to be deleted when Save() is called
in
BaseObject at line 855
bool
isCreated()
True if this object has been created and not yet saved to DB (should not be overriden)
in
StandardObject at line 51
static protected BaseObject
BaseCreate(ObjectDatabase $database)
Create the object by setting its created date
in
StandardObject at line 23
protected float
GetDate(string $name)
Returns the timestamp value stored in the given date field
in
StandardObject at line 29
protected float|null
TryGetDate(string $name)
Returns the timestamp value stored in the given date field
in
StandardObject at line 38
protected StandardObject
SetDate(string $name, float|null $value = null)
Sets the value of the given date field to the given value
in
StandardObject at line 44
float
GetDateCreated()
Returns the timestamp when this object was created
in
StandardObject at line 58
protected int
GetFeatureInt(string $name, bool $allowTemp = true)
Gets the value of the given feature field as an int (used for config)
in
StandardObject at line 65
protected int|null
TryGetFeatureInt(string $name, bool $allowTemp = true)
Gets the value of the given feature field as an int (used for config)
in
StandardObject at line 75
protected bool
GetFeatureBool(string $name, bool $allowTemp = true)
Gets the value of the given feature field as a bool (used for config)
in
StandardObject at line 82
protected bool|null
TryGetFeatureBool(string $name, bool $allowTemp = true)
Gets the value of the given feature field as a bool (used for config)
in
StandardObject at line 93
protected StandardObject
SetFeatureInt(string $name, int|null $value, bool $temp = false)
Sets the value of the given feature field to the given (?int) value
in
StandardObject at line 101
protected StandardObject
SetFeatureBool(string $name, bool|null $value, bool $temp = false)
Sets the value of the given feature field to the given (?bool) value
in
StandardObject at line 105
protected bool
isFeatureModified(string $name)
Returns true if the given feature has been modified
in
StandardObject at line 114
protected int
GetCounter(string $name)
Gets the value of the given counter field
in
StandardObject at line 121
protected int
GetCounterLimit(string $name)
Gets the value of the given counter limit field
in
StandardObject at line 128
protected int|null
TryGetCounterLimit(string $name)
Gets the value of the given counter limit field
in
StandardObject at line 140
protected StandardObject
SetCounterLimit(string $name, int|null $value, bool $temp = false)
Sets the value of the given counter limit field
in
StandardObject at line 151
protected bool
CheckCounter(string $name, int $delta = 0, bool $except = true)
Checks whether the given counter plus a delta would exceed the limit
in
StandardObject at line 202
protected array
GetAllScalars(string|null $prefix)
Gets an array of the values of all fields matching a prefix
in
FieldCrypt at line 22
abstract protected Account|null
GetAccount()
Returns the account that owns this object
in
FieldCrypt at line 25
abstract static array
LoadByAccount(ObjectDatabase $database, Account $account)
Returns all objects owned by the given account
in
BasePath at line 126
array
GetClientObject(bool $activate = false)
No description
in
BasePath at line 133
static string
GetCreateUsage()
No description
in
BasePath at line 135
static Storage
Create(ObjectDatabase $database, Input $input, FSManager $filesystem)
No description
in
BasePath at line 141
static string
GetEditUsage()
No description
in
Storage at line 110
Storage
Test()
Asserts that the underlying storage can be connected and read from/written to
in
Storage at line 124
bool
supportsFolders()
By default, most storages support using folders
in
Storage at line 127
bool
usesBandwidth()
By default, most storages use network bandwidth
in
Storage at line 130
bool
canGetFreeSpace()
Returns whether or not the storage supports getting free space
in
Storage at line 133
int
GetFreeSpace()
Returns the available space in bytes on the storage
in
Storage at line 136
abstract Storage
Activate()
Activates the storage by making any required connections
in
FWrapper at line 54
protected void
assertReadable()
Asserts that the filesystem root can be read
in
FWrapper at line 60
protected void
assertWriteable()
Asserts that the filesystem root can be written to
in
Storage at line 149
protected void
TestWriteable()
Manually tests if the root is writeable by uploading a test file
Can be used to implement assertWriteable() if no function exists
in
Storage at line 163
protected Storage
AssertNotReadOnly()
Asserts that the storage is not read only
in
Storage at line 175
protected bool
isDryRun()
Returns true if the server is set to dry run mode
in
Storage at line 190
int
getSize(string $path)
Returns the size of the file with the given path
in
FWrapper at line 44
bool
isFolder(string $path)
Returns true if the given path is a folder
in
FWrapper at line 49
bool
isFile(string $path)
Returns true if the given path is a file
in
Storage at line 203
array
ReadFolder(string $path)
Lists the contents of a folder
in
FWrapper at line 66
protected array
SubReadFolder(string $path)
The storage-specific ReadFolder
in
Storage at line 215
Storage
CreateFolder(string $path)
Asserts that the folder with the given path exists
in
FWrapper at line 73
protected Storage
SubCreateFolder(string $path)
The storage-specific CreateFolder
in
Storage at line 242
Storage
CreateFile(string $path)
Creates a new empty file at the given path
If it already exists, overwrites + NO ROLLBACK
in
FWrapper at line 80
protected Storage
SubCreateFile(string $path)
The storage-specific CreateFile
in
Storage at line 279
Storage
ImportFile(string $src, string $dest, bool $istemp)
Imports an existing file into the storage
If it already exists, overwrites + NO ROLLBACK
in
FWrapper at line 87
protected Storage
SubImportFile(string $src, string $dest, bool $istemp)
The storage-specific ImportFile
in
Storage at line 314
string
ReadBytes(string $path, int $start, int $length)
Reads data from a file
in
FWrapper at line 168
protected string
SubReadBytes(string $path, int $start, int $length)
The storage-specific ReadBytes
in
Storage at line 334
Storage
WriteBytes(string $path, int $start, string $data)
Writes data to a file
NO ROLLBACK if within existing bounds
in
FWrapper at line 179
protected Storage
SubWriteBytes(string $path, int $start, string $data)
The storage-specific WriteBytes
in
Storage at line 379
Storage
Truncate(string $path, int $length)
Truncates the file (changes size)
NO ROLLBACK if shrinking the file
in
FWrapper at line 96
protected Storage
SubTruncate(string $path, int $length)
The storage-specific Truncate
in
Storage at line 405
Storage
DeleteFile(string $path)
Deletes the file with the given path - NO ROLLBACK
in
FWrapper at line 111
protected Storage
SubDeleteFile(string $path)
The storage-specific DeleteFile
in
Storage at line 423
Storage
DeleteFolder(string $path)
Deletes the empty folder with the given path - NO ROLLBACK
in
FWrapper at line 120
protected Storage
SubDeleteFolder(string $path)
The storage-specific DeleteFolder
in
Storage at line 445
Storage
RenameFile(string $old, string $new)
Renames a file from $old to $new - path shall not change
NO ROLLBACK if overwriting an existing file
in
FWrapper at line 127
protected Storage
SubRenameFile(string $old, string $new)
The storage-specific RenameFile
in
Storage at line 479
Storage
RenameFolder(string $old, string $new)
Renames a folder from $old to $new - path shall not change
The destination folder must not already exist
in
FWrapper at line 136
protected Storage
SubRenameFolder(string $old, string $new)
The storage-specific RenameFolder
in
Storage at line 513
Storage
MoveFile(string $old, string $new)
Moves a file from $old to $new - name shall not change
NO ROLLBACK if overwriting an existing file
in
FWrapper at line 143
protected Storage
SubMoveFile(string $old, string $new)
The storage-specific MoveFile
in
Storage at line 547
Storage
MoveFolder(string $old, string $new)
Moves a folder from $old to $new - name shall not change
The destination folder must not already exist
in
FWrapper at line 152
protected Storage
SubMoveFolder(string $old, string $new)
The storage-specific MoveFolder
in
Storage at line 581
Storage
CopyFile(string $old, string $new)
Copies a file from $old to $new (path and name can change)
NO ROLLBACK if overwriting an existing file
in
FWrapper at line 159
protected Storage
SubCopyFile(string $old, string $new)
The storage-specific CopyFile
in
Storage at line 614
Storage
CopyFolder(string $old, string $new)
Copies a folder from $old to $new (path and name can change)
The destination folder must not already exist
in
Storage at line 640
protected Storage
SubCopyFolder(string $old, string $new)
The storage-specific CopyFolder
in
Storage at line 646
bool
canCopyFolders()
By default, most storages cannot copy whole folders
in
Storage at line 662
protected Storage
renameRollbacks(string $old, string $new)
Moves all pending rollback actions from $old to $new for delete tracking
in
Storage at line 680
protected Storage
deleteRollbacks(string $path)
Deletes all pending rollback actions for the given path
in
Storage at line 690
commit()
No description
in
Storage at line 699
rollback()
No description
in
Storage at line 709
static
commitAll()
Commits all instantiated filesystems
in
Storage at line 713
static
rollbackAll()
Rolls back all instantiated filesystems
in
FWrapper at line 35
abstract protected string
GetFullURL(string $path = "")
Returns the full fwrapper URL for the given path
in
FWrapper at line 194
static protected bool
supportsReadWrite()
Returns true if we can read from a stream opened as write
in
FWrapper at line 197
static protected bool
supportsSeekReuse()
Returns true if an already-open stream can be seeked randomly
in
FWrapper at line 200
protected
OpenReadHandle(string $path)
Returns a read handle for the given path
in
FWrapper at line 203
protected
OpenWriteHandle(string $path)
Returns a write handle for the given path
in
FWrapper at line 214
protected FileContext
OpenContext(string $path, int $offset, bool $isWrite)
Returns a new handle for the given path
in
FWrapper at line 232
protected FileContext
GetContext(string $path, int $offset, bool $isWrite)
Returns a context for the given file
in
FWrapper at line 264
protected void
ClosePath(string $path)
Closes any open handles for the given file path
in
BasePath at line 151
protected string
GetPath(string $path = "")
Returns the full storage level path for the given root-relative path
in
FieldCrypt at line 19
abstract static protected array
getEncryptedFields()
Returns the list of fields encrypted in this object
in
FieldCrypt at line 28
static array
GetFieldCryptFieldTemplate()
Gets the extra DB fields required for this trait
in
FieldCrypt at line 35
protected bool
isFieldEncrypted($field)
Returns true if the given DB field is encrypted
in
FieldCrypt at line 39
protected bool
isCryptoAvailable()
Returns true if field crypto is unlockable
in
FieldCrypt at line 55
protected string
GetEncryptedScalar(string $field)
Decrypts and returns the value of the given field
in
FieldCrypt at line 63
protected Account
RequireCrypto()
Unlocks account crypto for usage and returns it
in
FieldCrypt at line 78
protected string|null
TryGetEncryptedScalar(string $field)
Decrypts and returns the value of the given field
in
FieldCrypt at line 103
protected FieldCrypt
SetEncryptedScalar(string $field, string|null $value, bool|null $fieldcrypt = null)
Sets the value of the given field
in
FieldCrypt at line 129
protected FieldCrypt
SetEncrypted(bool $crypt)
Sets the crypto state of all stored fields
in
FieldCrypt at line 145
static void
DecryptAccount(ObjectDatabase $database, Account $account)
Loads any objects for the given account and decrypts their fields
in
OptFieldCrypt at line 161
static string
GetFieldCryptCreateUsage()
Returns the command usage for Create()
in
OptFieldCrypt at line 164
OptFieldCrypt
FieldCryptCreate(Input $input)
Performs cred-crypt level initialization on a new storage
in
OptFieldCrypt at line 172
static string
GetFieldCryptEditUsage()
Returns the command usage for Edit()
in
OptFieldCrypt at line 175
OptFieldCrypt
FieldCryptEdit(Input $input)
Performs cred-crypt level edit on an existing storage
in
OptFieldCrypt at line 185
array
GetFieldCryptClientObject()
Returns the printable client object of this trait
in
UserPass at line 71
protected string|null
TryGetUsername()
Returns the decrypted username
in
UserPass at line 74
protected string|null
TryGetPassword()
Returns the decrypted password