\QuickApps\Core\PackageGenericPackage

Represents an unknown package.

Generic packages doesn't have path nor version defined by default although they can be set using setters methods setVersion() and setPath().

Summary

Methods
Properties
Constants
setVersion()
setPath()
__construct()
name()
vendor()
version()
path()
versionMatch()
composer()
dependencies()
__toString()
cache()
dropCache()
No public properties found
No constants found
No protected methods found
$_defaultConfig
$_packageName
$_vendor
$_name
$_path
$_version
$_cache
N/A
No private methods found
No private properties found
N/A

Properties

$_defaultConfig

$_defaultConfig : array

Default config.

Type

array

$_packageName

$_packageName : string

Full package name. e.g. `vendor/package`

Type

string

$_vendor

$_vendor : string

Package vendor's name.

Type

string

$_name

$_name : string

Package's name, or plugin's name.

Type

string

$_path

$_path : string

Full path to package's root directory.

Type

string

$_version

$_version : string|null

Package's version number.

Type

string|null

$_cache

$_cache : array

Used internally.

Type

array

Methods

setVersion()

setVersion(string $version)

Sets a version number for this package.

Parameters

string $version

The version to set

setPath()

setPath(string $path)

Sets a package path for this package.

Parameters

string $path

Package file system path

__construct()

__construct(string $package, string $path, string $version)

Constructor.

Parameters

string $package

Package name as string. e.g. vendor-name/package-name

string $path

Full path to package's root directory

string $version

Package version number

name()

name() : string

Returns package's name, that if whatever comes after the `/` symbol.

Returns

string —

If $this represents a QuickAppsCMS's plugin, then its CamelizedName will be returned

vendor()

vendor() : string

Gets package's vendor name, that is whatever before the `/` symbol.

Returns

string —

If $this represents a QuickAppsCMS's plugin, then an empty string will be returned

version()

version() : string

Gets version number of this package.

Returns

string —

Package's version, for instance 1.2.x-dev

path()

path() : string

Returns full path to package's root directory.

Returns

string

versionMatch()

versionMatch(string $constraint) : boolean

Check whether this package's version matches the given $constraint.

Other package types might overwrite this method to provide their own matching logic.

Parameters

string $constraint

A string representing a dependency constraint, for instance, >7.0 || 1.2 or ~1.2

Returns

boolean

composer()

composer(boolean $full) : array

Gets composer json information for this package.

Parameters

boolean $full

Whether to get full composer schema or not. Defaults to false, only defined keys in JSON file will be fetched

Returns

array —

Package's "composer.json" file as an array, an empty array if corrupt or not found

dependencies()

dependencies() : array

Gets package's dependencies as an array list.

Example:

$this->dependencies();

// may returns: [
//    'some-vendor/user-work' => '1.0',
//    'another-vendor/calendar' => '1.0.*',
//    'quickapps/cms' => '>=1.0',
//    'php' => '>4.3',
//    'cakephp/cakephp' => '3.*',
// ]

Returns

array —

List of packages and versions this package depends on

__toString()

__toString() : string

String representation of this rule.

Returns

string

cache()

cache(null|string $key, mixed $value) : mixed

Reads, writes or search internal class's cache.

Usages:

  • When reading if no cache key is found NULL will be returned. e.g. $null = static::cache('invalid-key');
  • When writing, this method return the value that was written. e.g. $value = static::cache('key', 'value');
  • Set both arguments to NULL to read the whole cache content at the moment. e.g. $allCache = static::cache()
  • Set key to null and value to anything to find the first key holding the given value. e.g. $key = static::cache(null, 'search key for this value'), if no key for the given value is found NULL will be returned.

Examples:

Writing cache:

static::cache('user_name', 'John');
// returns 'John'

static::cache('user_last', 'Locke');
// returns 'Locke'

Reading cache:

static::cache('user_name');
// returns: John

static::cache('unexisting_key');
// returns: null

static::cache();
// Reads the entire cache
// returns: ['user_name' => 'John', 'user_last' => 'Locke']

Searching keys:

static::cache(null, 'Locke');
// returns: user_last

static::cache(null, 'Unexisting Value');
// returns: null

Parameters

null|string $key

Cache key to read or write, set both $key and $value to get the whole cache information

mixed $value

Values to write into the given $key, or null indicates reading from cache

Returns

mixed

dropCache()

dropCache(string|null $key) : void

Drops the entire cache or a specific key.

Usage:

static::dropCache('user_cache'); // removes "user_cache" only
static::dropCache(); // removes every key

Parameters

string|null $key

Cache key to clear, if NULL the entire cache will be erased.