Git
extends FileSystem
in package
Implement GIT database abstraction handler
This class provides interfaces for database handling. Using the installed git executable, this class provides some abstraction layers for handling GIT operations.
Tags
Table of Contents
- $affected : array<string|int, mixed>
- List of affected files and directories in recursion
- $default_hash : string
- empty git hash
- $folder : string
- the current folder
- $history_file : string
- The storage location of history file
- $log_template : string
- The template for log messages in ::Log()
- $size_unit : array<string|int, mixed>
- Available file size short codes
- __construct() : mixed
- construct new instance
- AddTag() : Result
- Add a tag
- AddUntracked() : Result
- Add not tracked
- AllKnownFiles() : Result
- get all files known to git load the list of files in the current index
- Branch() : string|null
- Get the current branch name
- Branches() : array<string|int, mixed>|null
- Get all locally available branches
- CalculateFolderSize() : array<string|int, mixed>
- Calculate size of a specific folder use a recursive working function to calculate a folder size
- CallExecutable() : Result
- Execute a system command Uses installed executable to perform a system call
- Chmod() : bool
- Change the permissions of a file
- CleanFolder() : Result
- Remove all not staged changes from local database will do a git clean -df on the given folder
- CommitAll() : Result
- Create commit over all
- CommitFile() : Result
- Commit a single file
- CommitFiles() : Result
- store the changed files update the git index by doing a commit
- CopyFile() : Result
- Copy file Copy a single file with obtaining lock on index before
- CopyFolder() : Result
- Copy folder contents
- CreateBranch() : Result
- Create a new branch and checkout
- Debug() : bool
- log debug object writs a formatted log message including back trace to the global log file
- DecodeJson() : Result
- Parse json from string to object or assoc
- DecodeJsonFile() : Result
- Parse json from file to object or assoc
- DeleteFile() : bool
- Deletes single file This method deletes a single file, it will wait when the system is in git lock mode
- DeleteFolder() : Result
- Stage folder drop will do a git add -u on the given folder
- DeleteHistoryCache() : Result
- Drop the history cache file
- DiffChangedFiles() : Result
- list changed files provide a list of changed files of git
- DropFolder() : array<string|int, mixed>
- Delete a full folder
- EncodeJson() : Result
- Serialize a given input to json representation
- ExtractExtension() : bool|string
- Extract file extension
- ExtractFileName() : string
- Extract file name
- ExtractFolder() : string
- Extract folder path from root
- ExtractFolderName() : string
- Extract folder name from root
- FileExists() : bool|string
- Check if file exists
- FileRefLog() : Result
- get the version list of a certain file loads the list of commits that affected a certain file
- FileRefParse() : Result
- get the values of version of a certain file loads the file content at a certain version
- FilterFolderFilesByModificationTime() : Result
- Get a list of files that are either older or newer a certain time point
- GetConfigOption() : Result
- get a config option use git config to load a certain option
- GetCreationTime() : Result
- Get the creation tim of a file
- GetHistoryCache() : Result
- get the history file load the list of changes before last call
- GetLastRecentHash() : Result
- get the last commit that affected a file loads the id of the last commit or the default value when file is not known to git
- GetLastRecentHashes() : Result
- Get commit list that affected a file loads the id list of the commits that affected a file
- GetLatestCommit() : string
- Get the latest commit hash of the system Uses log function to get the latest commit
- GetLatestTag() : string
- Get the latest tag of the system Uses the describe function to get the latest tag
- GetLock() : Result
- Obtain lock try to obtain the lock indicated by lock file in var
- GetObjectLock() : bool
- Get lock on certain object
- HasChanges() : Result
- IsEmptyDir() : bool|null
- Is empty folder
- ListChangedFiles() : Result
- list changed files provide a list of not tracked files of git
- ListFiles() : array<string|int, mixed>
- list files Iterate over directory and list the found files
- ListFolders() : array<string|int, mixed>
- List folder names in certain root folder
- ListIdFiles() : array<string|int, mixed>
- Find file ids
- ListNotPushedCommits() : Result
- List not pushed commits
- Log() : bool
- log object writs a formatted log message including back trace to the global log file
- MemoryBytesReadable() : string
- Memory readable Convert size of bytes in human-readable units
- MkFolder() : string|null
- Create folder path
- ObjectType() : string|null
- Get type of git object
- OpenCommit() : Commit|null
- Open the commit based on an id
- PrintObject() : string|null
- Parse a git object
- Pull() : Result
- pull the changes from remote load and update all commits from remote server
- Push() : Result
- push the changes to remote push all outgoing commits to remote server
- ReadCsv() : Result
- Read a CSV file to local storage
- ReadFile() : Result
- Read a single file
- ReadFixedColumnFile() : Result
- Read file with fixed column width
- ReadFolder() : array<string|int, File>
- Read folder
- RemoteReachable() : Result
- check if server is reachable does a ping to the storage server using ls remote
- RenameFolderOrFile() : Result
- Rename folder or file
- ResolveChain() : array<string|int, Commit>
- Get list of all parental commits based on a certain reference
- RevokeLock() : Result
- release lock try to release the lock indicated by lock file in var
- RevokeObjectLock() : Result
- Revoke dedicated object lock
- SelfLockedOrOpen() : bool
- SetHistoryCache() : Result
- store the history file update the list of changes after sync call
- StageFile() : Result
- Stage changes into local database
- StageFolder() : Result
- Stage changes into local database
- StoreEncodedJson() : Result
- Serialize a given input and store it
- StripQueryAndAnchor() : string
- Extract file name
- SysLog() : bool
- Log message
- TryGetLock() : bool
- Obtain lock with retry
- Version() : Result
- get the version of git executable loads the version string
- VersionStringToNumber() : string
- Convert version number Converts the given number to a unified string e.g. 'v1.234.33' will become 102340033
- VersionTagList() : Result
- Get the system version tags
- Warn() : bool
- warn level log object writs a formatted log message including back trace to the global log file
- WriteCsv() : Result
- Write an array of entries to csv file
- WriteFile() : bool
- Write string to file
- CalculateFolderSizeRecurse() : bool
- Helper function to calculate size Recursively calculate size of a specific folder
- callGitExecutable() : Result
- Execute a git command
- decrypt() : string
- Decrypt data
- DropFolderRecurse() : bool
- Delete a folder completely this method is the recursion helper for DropFolder()
- encrypt() : string
- Encrypt data
- parseKeyFile() : string|array<string|int, mixed>|null
Properties
$affected
List of affected files and directories in recursion
private
static array<string|int, mixed>
$affected
= array()
The list of paths
$default_hash
empty git hash
private
string
$default_hash
= FAA_GIT_DEFAULT_HASH
The default empty git hash
$folder
the current folder
private
string
$folder
= ''
The current folder
$history_file
The storage location of history file
private
string
$history_file
= ''
The storage location of history file
$log_template
The template for log messages in ::Log()
private
static string
$log_template
= "Called from LINE %s IN Script: %s\n"
The template
$size_unit
Available file size short codes
private
static array<string|int, mixed>
$size_unit
= array('b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb')
Used in the readable form
Methods
__construct()
construct new instance
public
__construct([string $folder = FAA_PATHS_DATAABS ]) : mixed
Open new repository instance
Parameters
- $folder : string = FAA_PATHS_DATAABS
-
The absolute path to the repository to open
Return values
mixed —AddTag()
Add a tag
public
AddTag(string $name, string $msg[, string|null $commit = null ][, bool $force = false ]) : Result
Adds a tag to the current commit given the name and a message. With commit and force flag it is possible to overwrite/move tags
Parameters
- $name : string
-
The tag name e.g. v1.0.0
- $msg : string
-
The tag message
- $commit : string|null = null
-
A certain commit
- $force : bool = false
-
When commit is given, and this is true it will force the tag
Return values
Result —A system result object
AddUntracked()
Add not tracked
public
AddUntracked() : Result
Will do add of not tracked files, this requires an alias in the git configuration
Return values
Result —a default system result object
AllKnownFiles()
get all files known to git load the list of files in the current index
public
AllKnownFiles() : Result
Return values
Result —a default system result object
Branch()
Get the current branch name
public
Branch() : string|null
Return values
string|null —Branches()
Get all locally available branches
public
Branches() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null —CalculateFolderSize()
Calculate size of a specific folder use a recursive working function to calculate a folder size
public
static CalculateFolderSize(string $folder) : array<string|int, mixed>
Parameters
- $folder : string
-
The path to calculate the size of
Return values
array<string|int, mixed> —An assoc structure holding the folder information
CallExecutable()
Execute a system command Uses installed executable to perform a system call
public
static CallExecutable(string $cmd[, string $folder = '' ][, string $outfile = '' ]) : Result
Parameters
- $cmd : string
-
The command to execute
- $folder : string = ''
-
The working directory
- $outfile : string = ''
-
Optional output file of the call result
Return values
Result —A system result object
Chmod()
Change the permissions of a file
public
static Chmod(string $file, int $octal) : bool
Parameters
- $file : string
- $octal : int
Return values
bool —CleanFolder()
Remove all not staged changes from local database will do a git clean -df on the given folder
public
CleanFolder(string $folder) : Result
Parameters
- $folder : string
-
Relative path to stage target
Return values
Result —A default system result object
CommitAll()
Create commit over all
public
CommitAll(string $msg) : Result
Create a commit with the -a option and sets the given message. Will fail when no local changes are available
Parameters
- $msg : string
-
The commit message
Return values
Result —A system result object
CommitFile()
Commit a single file
public
CommitFile(string $file, string $msg[, bool $amend = false ]) : Result
Adds the given file and commits it with the given message. The amend function will only work if at least one local commit is remaining.
Parameters
- $file : string
-
The relative file path
- $msg : string
-
The commit message
- $amend : bool = false
-
When true the commit will be added to the last unpushed commit
Return values
Result —A system result object
CommitFiles()
store the changed files update the git index by doing a commit
public
CommitFiles(array<string|int, mixed> $files[, CronJob &$job = null ]) : Result
Parameters
- $files : array<string|int, mixed>
-
A list of relative filepaths to commit
- $job : CronJob = null
-
When running in job context, the cronjob instance otherwise false or null
Return values
Result —A default system result object
CopyFile()
Copy file Copy a single file with obtaining lock on index before
public
static CopyFile(string $source, string $target[, bool $override = true ]) : Result
Parameters
- $source : string
-
Absolute path to source
- $target : string
-
Absolute path to target
- $override : bool = true
-
Override forced even if file names are equal
Return values
Result —A system result object
CopyFolder()
Copy folder contents
public
static CopyFolder(string $source, string $target[, bool $override = true ]) : Result
This method copies the source folder to the target folder path. The folder itself is not copied but all of its contents. This method creates the target folder if it is not present.
Parameters
- $source : string
-
The source folder destination
- $target : string
-
The target folder name
- $override : bool = true
-
Override forced even if file names are equal
Return values
Result —A system result object
CreateBranch()
Create a new branch and checkout
public
CreateBranch( $name) : Result
Parameters
Return values
Result —Debug()
log debug object writs a formatted log message including back trace to the global log file
public
static Debug(mixed $object) : bool
Parameters
- $object : mixed
-
The object to be logged
Return values
bool —DecodeJson()
Parse json from string to object or assoc
public
static DecodeJson(string $data[, bool $mode = true ][, array<string|int, mixed>|string|null $crypt = null ]) : Result
Use the json parse function to decode a string to assoc or object It will use the given code in crypt to decrypt or fall back to system key
Parameters
- $data : string
-
The payload to decode
- $mode : bool = true
-
Parse as assoc or object, default is true and therefor assoc array
- $crypt : array<string|int, mixed>|string|null = null
-
The key or, an array with cipher, key and the iv
Return values
Result —A default system result object
DecodeJsonFile()
Parse json from file to object or assoc
public
static DecodeJsonFile(string $path[, bool $mode = true ][, string|null $crypt = null ]) : Result
Use the json parse to fetch text data from a given path and return it as object with assoc or object payload
Parameters
- $path : string
-
The absolute path to a certain storage file
- $mode : bool = true
-
Parse as assoc or object, default assoc
- $crypt : string|null = null
-
Decrypt string before parsing
Return values
Result —A default system result object
DeleteFile()
Deletes single file This method deletes a single file, it will wait when the system is in git lock mode
public
static DeleteFile(string $path) : bool
Parameters
- $path : string
-
The target file path
Return values
bool —True on success otherwise false
DeleteFolder()
Stage folder drop will do a git add -u on the given folder
public
DeleteFolder(string $folder) : Result
Parameters
- $folder : string
-
Relative path to stage target
Return values
Result —A default system result object
DeleteHistoryCache()
Drop the history cache file
public
DeleteHistoryCache() : Result
Return values
Result —DiffChangedFiles()
list changed files provide a list of changed files of git
public
DiffChangedFiles(string $hash) : Result
Parameters
- $hash : string
-
The start hash to check from
Return values
Result —A default system result object
DropFolder()
Delete a full folder
public
static DropFolder(string $folder[, bool $full = false ]) : array<string|int, mixed>
this method clears or delete a folder recursively, side effect will fill list of delete folders and files
Parameters
- $folder : string
-
The path to delete
- $full : bool = false
-
Also remove the root folder
Return values
array<string|int, mixed> —List of deleted folders and files
EncodeJson()
Serialize a given input to json representation
public
static EncodeJson(mixed $data[, int $mode = JSON_PRETTY_PRINT ][, array<string|int, mixed>|string|null $crypt = null ]) : Result
use the json parse function to decode an assoc or object
Parameters
- $data : mixed
-
The payload to encode
- $mode : int = JSON_PRETTY_PRINT
-
Serialize readable or not formatted
- $crypt : array<string|int, mixed>|string|null = null
-
Encrypt key or, array with key cipher and iv
Return values
Result —A default system result object
ExtractExtension()
Extract file extension
public
static ExtractExtension(string $path) : bool|string
May return false if no extension could be found
Parameters
- $path : string
-
A complete file path
Return values
bool|string —The file extension or, false if not matched
ExtractFileName()
Extract file name
public
static ExtractFileName(string $path[, bool $without_extension = false ]) : string
Parameters
- $path : string
-
A complete file path
- $without_extension : bool = false
Return values
string —The file name
ExtractFolder()
Extract folder path from root
public
static ExtractFolder(string $path) : string
With input /var/www/school/test.json will result in /var/www/school/
Parameters
- $path : string
-
A complete file path
Return values
string —The file root folder
ExtractFolderName()
Extract folder name from root
public
static ExtractFolderName(string $path) : string
Parameters
- $path : string
-
A complete file path
Return values
string —The file root folder
FileExists()
Check if file exists
public
static FileExists(string $fileName[, bool $caseSensitive = true ]) : bool|string
Does check if a file is existing, will also check if the file exists as lower case by glob as fallback.
Parameters
- $fileName : string
-
The path to the file
- $caseSensitive : bool = true
-
Use case-sensitive path, defaults to true
Return values
bool|string —File exists
FileRefLog()
get the version list of a certain file loads the list of commits that affected a certain file
public
FileRefLog(string $path) : Result
Parameters
- $path : string
-
The relative path to the file to check
Return values
Result —A default system result object
FileRefParse()
get the values of version of a certain file loads the file content at a certain version
public
FileRefParse(string $hash, string $path) : Result
Parameters
- $hash : string
-
The GIT commit hash to load at
- $path : string
-
The relative path to the file to check
Return values
Result —A default system result object
FilterFolderFilesByModificationTime()
Get a list of files that are either older or newer a certain time point
public
static FilterFolderFilesByModificationTime(string $root, int $timestamp[, bool $older = true ]) : Result
Parameters
- $root : string
-
The start point for the recursion
- $timestamp : int
-
The time point to flip
- $older : bool = true
-
When true result list files are older than the time stamp otherwise newer
Return values
Result —A system result object containing the files
GetConfigOption()
get a config option use git config to load a certain option
public
GetConfigOption(string $key) : Result
Parameters
- $key : string
-
The option to load
Return values
Result —A default system result object
GetCreationTime()
Get the creation tim of a file
public
GetCreationTime(string $path) : Result
will try to use index, but when file not indexed a atime call is done
Parameters
- $path : string
-
The relative path to the file to check
Return values
Result —A default system result object
GetHistoryCache()
get the history file load the list of changes before last call
public
GetHistoryCache() : Result
Return values
Result —a default system result object
GetLastRecentHash()
get the last commit that affected a file loads the id of the last commit or the default value when file is not known to git
public
GetLastRecentHash([string $path = '' ]) : Result
Parameters
- $path : string = ''
-
The relative path to the file to check or null for whole repository
Return values
Result —A default system result object
GetLastRecentHashes()
Get commit list that affected a file loads the id list of the commits that affected a file
public
GetLastRecentHashes([string $path = '' ][, int $count = 1000 ]) : Result
Parameters
- $path : string = ''
-
The relative path to the file to check or null for whole repository
- $count : int = 1000
-
The maximum length of history lines to return
Return values
Result —A default system result object
GetLatestCommit()
Get the latest commit hash of the system Uses log function to get the latest commit
public
GetLatestCommit([int $len = 7 ]) : string
Parameters
- $len : int = 7
-
Characters length to return from hash
Return values
string —The latest commit
GetLatestTag()
Get the latest tag of the system Uses the describe function to get the latest tag
public
GetLatestTag() : string
Return values
string —the latest version tag
GetLock()
Obtain lock try to obtain the lock indicated by lock file in var
public
static GetLock() : Result
Return values
Result —A default system result object
GetObjectLock()
Get lock on certain object
public
static GetObjectLock(BaseContent $content) : bool
Lock could be obtained, it will return true otherwise false. Uses the system default method "in memory"
Parameters
- $content : BaseContent
-
A system content
Tags
Return values
bool —HasChanges()
public
HasChanges([null $file = null ]) : Result
Parameters
- $file : null = null
Return values
Result —IsEmptyDir()
Is empty folder
public
static IsEmptyDir(string $dir) : bool|null
Parameters
- $dir : string
-
Path to folder
Return values
bool|null —ListChangedFiles()
list changed files provide a list of not tracked files of git
public
ListChangedFiles([bool $auto_add = false ]) : Result
Parameters
- $auto_add : bool = false
-
Automatic add files that are currently untracked
Return values
Result —A default system result object
ListFiles()
list files Iterate over directory and list the found files
public
static ListFiles(string $dir[, string $ext = '/^json$/' ][, bool $full = false ]) : array<string|int, mixed>
Parameters
- $dir : string
-
The root folder path to search in
- $ext : string = '/^json$/'
-
Filter by extension (can be empty, a string or a regex)
- $full : bool = false
-
Check the full name of the file or just the extension when false
Return values
array<string|int, mixed> —A list containing the found files
ListFolders()
List folder names in certain root folder
public
static ListFolders(string $path) : array<string|int, mixed>
Parameters
- $path : string
-
The absolute path to the folder
Return values
array<string|int, mixed> —The found folder names that are children of the given folder
ListIdFiles()
Find file ids
public
static ListIdFiles(string $dir[, string $ext = 'json' ][, bool $to_int = true ]) : array<string|int, mixed>
Fetch a list of file ids inside a folder and its subdirectories
Parameters
- $dir : string
-
The root folder path to search in
- $ext : string = 'json'
-
Filter by extension
- $to_int : bool = true
-
Convert to integer when set to true
Return values
array<string|int, mixed> —A list containing the found id's
ListNotPushedCommits()
List not pushed commits
public
ListNotPushedCommits([string $branch = 'master' ]) : Result
The list will contain values like this if there are not pushed commits to the given branch 60f2a80b58c19183c73d1189e26baee22715170c [Wed, 22 Aug 2018 11:37:36 +0200] CHG: Make sure to amend only when commits are not pushed yet bfd98c345a6ebb345965c2451b32b785e0bc60c3 [Wed, 22 Aug 2018 11:23:44 +0200] ADD: Integrate solution to do something
Parameters
- $branch : string = 'master'
Return values
Result —Log()
log object writs a formatted log message including back trace to the global log file
public
static Log(mixed $object[, string|null $msg = null ]) : bool
Parameters
- $object : mixed
-
The object to be logged
- $msg : string|null = null
-
Additional message
Return values
bool —MemoryBytesReadable()
Memory readable Convert size of bytes in human-readable units
public
static MemoryBytesReadable(int|float $size) : string
Parameters
- $size : int|float
-
The size in bytes
Return values
string —The calculated size
MkFolder()
Create folder path
public
static MkFolder(string $root, array<string|int, mixed> $components[, bool $make = true ]) : string|null
When the make argument set to true this function will try to create the folder Return the folder components without root part
Parameters
- $root : string
-
The path to the base folder
- $components : array<string|int, mixed>
-
The list of folder components
- $make : bool = true
-
Try to create the folder
Return values
string|null —The combined relative path as string, includes tailing /
ObjectType()
Get type of git object
public
ObjectType( $object_id) : string|null
Parameters
Return values
string|null —OpenCommit()
Open the commit based on an id
public
OpenCommit(string $object_id) : Commit|null
Parameters
- $object_id : string
-
The git hash
Return values
Commit|null —A commit object or null
PrintObject()
Parse a git object
public
PrintObject(string $object_id) : string|null
Parameters
- $object_id : string
-
A 40 digit git object id
Return values
string|null —The parsed result or null on error
Pull()
pull the changes from remote load and update all commits from remote server
public
Pull([CronJob|null $job = null ]) : Result
Parameters
- $job : CronJob|null = null
-
When running in job context, the cronjob instance otherwise false or null
Return values
Result —A default system result object
Push()
push the changes to remote push all outgoing commits to remote server
public
Push([CronJob $job = null ][, string $args = null ]) : Result
Parameters
- $job : CronJob = null
-
When running in job context, the cronjob instance otherwise false or null
- $args : string = null
-
Additional command line arguments
Return values
Result —A default system result object
ReadCsv()
Read a CSV file to local storage
public
static ReadCsv(string $path[, string $delimiter = ';' ][, string $enclosure = "'" ][, int $length = 100000 ][, string $escape = "\" ][, bool $check_head = true ]) : Result
Fetch the file and add it to a local result object file is parsed with php function to get csv from file, arguments of this method align with official one
Parameters
- $path : string
-
The absolute path to file to open
- $delimiter : string = ';'
-
Have a look at http://php.net/manual/de/function.fgetcsv.php delimiter
- $enclosure : string = "'"
-
Have a look at http://php.net/manual/de/function.fgetcsv.php enclosure
- $length : int = 100000
-
Have a look at http://php.net/manual/de/function.fgetcsv.php length
- $escape : string = "\"
-
Have a look at http://php.net/manual/de/function.fgetcsv.php escape
- $check_head : bool = true
-
When set, check the first line as head and validate following line lengths
Return values
Result —A system result object
ReadFile()
Read a single file
public
static ReadFile(string $path) : Result
Parameters
- $path : string
-
The absolute path to a certain storage file
Return values
Result —A default system result object
ReadFixedColumnFile()
Read file with fixed column width
public
static ReadFixedColumnFile(string $path[, int $length = 10000 ]) : Result
Automatic file parser based on the heads and assuming a " " space is used to make the cols equal
Parameters
- $path : string
-
Absolute link to the file to open
- $length : int = 10000
-
Limiter for line length
Return values
Result —A system result object
ReadFolder()
Read folder
public
static ReadFolder(string $dir) : array<string|int, File>
Will list all files and folders of a folder
Parameters
- $dir : string
-
Path to root folder
Return values
array<string|int, File> —An array of file objects
RemoteReachable()
check if server is reachable does a ping to the storage server using ls remote
public
RemoteReachable() : Result
Return values
Result —a default system result object
RenameFolderOrFile()
Rename folder or file
public
static RenameFolderOrFile(string $source, string $target[, bool $skip_existing = true ]) : Result
Parameters
- $source : string
-
Absolute path to source
- $target : string
-
Absolute path to target
- $skip_existing : bool = true
Return values
Result —A system result object
ResolveChain()
Get list of all parental commits based on a certain reference
public
ResolveChain(string $ref) : array<string|int, Commit>
Parameters
- $ref : string
-
The start point
Return values
array<string|int, Commit> —The list of found commits
RevokeLock()
release lock try to release the lock indicated by lock file in var
public
static RevokeLock([string|null $lockfile = null ][, bool $in_memory = true ]) : Result
Parameters
- $lockfile : string|null = null
- $in_memory : bool = true
Return values
Result —A default system result object
RevokeObjectLock()
Revoke dedicated object lock
public
static RevokeObjectLock(BaseContent $content) : Result
Parameters
- $content : BaseContent
Tags
Return values
Result —SelfLockedOrOpen()
public
static SelfLockedOrOpen( $pid[, $path = null ]) : bool
Parameters
Return values
bool —SetHistoryCache()
store the history file update the list of changes after sync call
public
SetHistoryCache(array<string|int, mixed> $data) : Result
Parameters
- $data : array<string|int, mixed>
-
A list of commit hashes
Return values
Result —A default system result object
StageFile()
Stage changes into local database
public
StageFile(string $file[, bool $rm = false ]) : Result
Can either remove or add changed files to index. Files to add need to be existing Files to remove have to be deleted before from file system
Parameters
- $file : string
-
Relative path to stage target
- $rm : bool = false
-
When true, delete from index
Return values
Result —A system result object
StageFolder()
Stage changes into local database
public
StageFolder(string $folder) : Result
will do a git add -u on the given folder it will automatically add /* so hidden files won't be affected
Parameters
- $folder : string
-
Relative path to stage target
Return values
Result —A default system result object
StoreEncodedJson()
Serialize a given input and store it
public
static StoreEncodedJson(string $path, mixed $data[, int $mode = JSON_PRETTY_PRINT ][, bool|null $crypt = false ]) : Result
use the json parse function to create json representation and store it in a certain file this method does an encryption also on demand, the .key file must exist for this to happen
Parameters
- $path : string
-
The target file path
- $data : mixed
-
The payload to encode
- $mode : int = JSON_PRETTY_PRINT
-
Serialize readable or not formatted
- $crypt : bool|null = false
-
Encrypt the result after serialisation
Return values
Result —A default system result object
StripQueryAndAnchor()
Extract file name
public
static StripQueryAndAnchor(string $path) : string
Parameters
- $path : string
-
A complete file path
Return values
string —The file name without additional parts
SysLog()
Log message
public
static SysLog(string $level, mixed $object[, string|null $prefix = null ][, bool $stack = true ]) : bool
Writs a formatted log message including back trace on severe levels to the global log file
Parameters
- $level : string
-
Name of the log level
- $object : mixed
-
The object to be logged
- $prefix : string|null = null
-
Extra prefix
- $stack : bool = true
-
Print with stack trace on demand
Return values
bool —Status if write to log worked
TryGetLock()
Obtain lock with retry
public
static TryGetLock([string|null $path = null ][, string|int|null $pid = null ][, int $try_count = FAA_WRITE_RETRY ][, float $seconds = 0.25 ][, bool $in_memory = true ]) : bool
Try to obtain the lock indicated by lock file in var Additional lock level reliability with process id
Parameters
- $path : string|null = null
-
The lock file path or null for default
- $pid : string|int|null = null
-
The current process id locking the file
- $try_count : int = FAA_WRITE_RETRY
-
Retry counter
- $seconds : float = 0.25
-
Retry wait
- $in_memory : bool = true
-
Instead of file system use redis as lock file storage
Tags
Return values
bool —Version()
get the version of git executable loads the version string
public
Version() : Result
Return values
Result —A default system result object
VersionStringToNumber()
Convert version number Converts the given number to a unified string e.g. 'v1.234.33' will become 102340033
public
static VersionStringToNumber(string $number[, string $regex = '/[^0-9\.]/i' ][, string $replace = '' ][, int $pads = 4 ]) : string
Parameters
- $number : string
-
The version number to calculate
- $regex : string = '/[^0-9\.]/i'
-
Replacement expression to clear the number upfront
- $replace : string = ''
-
Replacement string for regex_replace
- $pads : int = 4
-
Add this amount of zeros to the left
Return values
string —The cleared version number
VersionTagList()
Get the system version tags
public
VersionTagList([string $path = 'v' ]) : Result
Uses for-each-ref to load and parse a list of tgs to Tag objects
Parameters
- $path : string = 'v'
-
The selection string of paths to search in index
Return values
Result —A system result object
Warn()
warn level log object writs a formatted log message including back trace to the global log file
public
static Warn(mixed $object[, bool $stack = true ]) : bool
Parameters
- $object : mixed
-
The object to be logged
- $stack : bool = true
Return values
bool —WriteCsv()
Write an array of entries to csv file
public
static WriteCsv(string|null $path, array<string|int, mixed> $list[, string $delimiter = ';' ][, string $enclosure = "'" ][, string $escape = "\" ]) : Result
Parameters
- $path : string|null
-
The absolute path to file to open
- $list : array<string|int, mixed>
-
The source to write
- $delimiter : string = ';'
-
Have a look at http://php.net/manual/de/function.fgetcsv.php delimiter
- $enclosure : string = "'"
-
Have a look at http://php.net/manual/de/function.fgetcsv.php enclosure
- $escape : string = "\"
-
Have a look at http://php.net/manual/de/function.fgetcsv.php escape
Return values
Result —The result
WriteFile()
Write string to file
public
static WriteFile(string $path, scalar $data, int $flags) : bool
This method writes the given data to the defined file, it will wait when the system is in git lock mode. This method returns valid result also for writing empty strings unlike file put contents default behavior
Parameters
- $path : string
-
The target file path
- $data : scalar
-
The payload to store in the target file
- $flags : int
-
File put content flags (http://php.net/manual/de/function.file-put-contents.php)
Return values
bool —True on success
CalculateFolderSizeRecurse()
Helper function to calculate size Recursively calculate size of a specific folder
private
static CalculateFolderSizeRecurse(string $folder, int &$file_count, int &$directory_count, int &$size) : bool
Parameters
- $folder : string
-
The path to calculate the size of
- $file_count : int
-
Pointer to file count
- $directory_count : int
-
Pointer to folder count
- $size : int
-
Pointer to file size
Return values
bool —The iteration result status
callGitExecutable()
Execute a git command
private
callGitExecutable(string $cmd[, string $outfile = '' ][, bool $lock = false ]) : Result
Uses installed git executable to do index operations
Parameters
- $cmd : string
-
The command to execute
- $outfile : string = ''
-
Optional output file of the call result
- $lock : bool = false
-
Optional, lock exclusive on demand
Return values
Result —A system result object
decrypt()
Decrypt data
private
static decrypt(string $encrypted[, string|array<string|int, mixed> $mc_key = FAA_CODE ]) : string
will try to decrypt the given data with the system encryption code or a customer defined one The function does a blowfish decryption and a base64 conversion on demand
Parameters
- $encrypted : string
-
The string to decrypt (must be base64 encoded)
- $mc_key : string|array<string|int, mixed> = FAA_CODE
-
The key or, an array with cipher, key and the iv
Tags
Return values
string —The decrypted string
DropFolderRecurse()
Delete a folder completely this method is the recursion helper for DropFolder()
private
static DropFolderRecurse(string $folder[, bool $full = false ]) : bool
Parameters
- $folder : string
-
The path to delete
- $full : bool = false
-
Also remove the root folder
Return values
bool —The delete status
encrypt()
Encrypt data
private
static encrypt(string $plain[, string|array<string|int, mixed> $mc_key = FAA_CODE ][, mixed &$tag = null ]) : string
Method will try to encrypt the given data with the system encryption code or a customer defined one The function does a blowfish encryption and a base64 conversion
Parameters
- $plain : string
-
The string to encrypt
- $mc_key : string|array<string|int, mixed> = FAA_CODE
-
The key or, an array with cipher, key and the iv
- $tag : mixed = null
Tags
Return values
string —The encrypted string base64 encoded
parseKeyFile()
private
static parseKeyFile(string $path) : string|array<string|int, mixed>|null
Parameters
- $path : string