-
Notifications
You must be signed in to change notification settings - Fork 5
Helper
The Amend helper retrieves a project repository's available downloads from GitHub (v3 API).
- getDownloads
- getFile
- getLatest
- getVersion
- setExtractor
- setIntegrityChecker
- setLock
- setMatcher
- setURL
- setVersion
<?php $list = $helper->getDownloads()
The getDownloads
method returns the list of downloads (an array of download details arrays) found from the repository.
In addition the data returned by the GitHub API, a new key is added to each download item called version
. The version
entry contains an instance of KevinGH\Version\Version
with the version that was extracted using the callable set by setExtractor
.
<?php $path = $helper->getFile($download);
The getFile
method downloads the file specified by $download
to a temporary location and returns the file path.
The $download
argument is one of entries in the array returned by the getDownloads
method. Once the file has been downloaded, the callable set by setIntegrityChecker
is called, and the file path passed to it. If the callable returns false
, an exception will be thrown stating the download was corrupted.
<?php $download = $helper->getLatest($lock);
The getLatest
method returns the most recent version (as defined by setVersion
of the relevant download contained in the list returned by getDownloads
.
By default, the download returned respects the major version lock set by setLock
. If true
is passed as $lock
, newer major versions will be allowed for return. If false
is set, only a download from within the same major version will be returned.
<?php $version = $helper->getVersion();
The getVersion
method returns the KevinGH\Version\Version
instance set by setVersion
.
<?php $helper->setExtractor($callable);
The setExtractor
method sets the callable used to extract version numbers from download items.
When the $callable
is used, the download item (an array of download details) is passed to $callable
. A string is expected which will then be parsed by the KevinGH\Version\Version
class.
<?php $helper->setIntegrityChecker($callable);
The setIntegrityChecker
sets the callable used to verify the integrity of a downloaded file.
The $callable
is passed the temporary file path of a downloaded item. If the download is corrupted, or unacceptable for any reason, false
is expected to be returned. The callable may, however, thrown an exception to provide more detail about why a download is unacceptable or corrupt.
<?php $helper->setLock($lock);
The setLock
method sets the default major version lock flag.
If true
is passed, only downloads within the same major version are used. If false
is passed, any download newer than the current major version are used.
<?php $helper->setMatcher($callable);
The setMatcher
method sets the callable used to filter out irrelevant downloads found by getDownloads
.
The matcher is passed a download item (an array of details for a download). If true
is returned, the download is kept. If false
is returned, the download is filtered out and discarded.
<?php $helper->setURL($url);
The setURL
method sets the base GitHub API URL that is used by getDownloads
.
The $url
is expected to be something like: https://api.github.com/repos/kherge/Box
<?php $helper->setVersion($version);
The setVersion
method sets the application's version.
$version
may be either a semantic version string, or an instance of KevinGH\Version\Version
. The instance is used by getLatest
to determine if a download is applicable to the current major version.