PHP Class Craft\MinimeeService

Inheritance: extends craft\BaseApplicationComponent
Datei anzeigen Open project: johndwells/craft.minimee

Protected Properties

Property Type Description
$_assets the trigger we use for our own resources
$_cacheBase css or js
$_cacheTimestamp a concat of all asset filenames together
$_deprecatedSettingsMap static array of settings, a merge of DB and filesystem settings
$_pluginSettings instance of Minimee_SettingsModel
$_settings max timestamp of all assets
$_type array of Minimee_AssetModelInterface

Public Methods

Method Description
deleteExpiredCache ( ) : void Based on the cache's hashed base, attempts to delete any older versions of same name.
init ( ) : void During startup, fetch settings from our plugin / config
makePathToStorageFolder ( ) : String
makeTagsByType ( String $type, Array $assets = [] ) : String Generate the HTML tag based on type
makeTwigMarkupFromHtml ( $html ) : Twig_Markup Wrapper for how we must return a twig option rather than raw HTML
run ( String $type, Array $assets, Array $settings = [] ) : Array | Bool Main service function that encapsulates an entire Minimee run

Protected Methods

Method Description
abort ( String $e, String $level = LogLevel::Error ) : Bool Internal function used when aborting due to error
appendToCacheBase ( String $name ) : Void Append an asset's name to the cacheBase
cacheExists ( ) : Bool Checks if the cache exists.
checkHeaders ( ) : this Validate all assets prior to run.
createCache ( ) : boolean Creates cache of assets.
ensureCacheExists ( ) : MinimeeService Fetch or creates cache.
flightcheck ( ) : this Perform pre-flight checks to ensure we can run.
getAssets ( ) : Array
getCacheBase ( ) : string
getCacheTimestamp ( ) : String
getPluginSettings ( ) : Array get our plugin / config settings
getSettings ( ) : Minimee_SettingsModel
getType ( ) : String
initPluginSettings ( ) : Void Fetch settings from our plugin / config
isCombineEnabled ( ) : boolean | null Return whether we should combine our cache or not
isUrl ( $string ) : boolean Determine if string is valid URL
makeCacheFilename ( ) : String Returns a complete cache filename.
makeHashOfCacheBase ( ) : String
makePathToCacheFilename ( ) : String
makePathToHashOfCacheBase ( ) : String
makeReturn ( ) : String
makeUrlToCacheFilename ( ) : String
minifyAsset ( Minimee_BaseAssetModel $asset ) : String Given an asset, fetches and returns minified contents.
minifyCssAsset ( Minimee_BaseAssetModel $asset ) : String Method to (maybe) minify CSS asset
minifyJsAsset ( Minimee_BaseAssetModel $asset ) : String Method to (maybe) minify JS asset
onCreateCache ( $event ) : Void Raise our 'onCreateCache' event
reset ( ) : this Safely resets service to prepare for a clean run.
setAssets ( Array $assets ) : this
setCacheBase ( String $name ) : MinimeeService
setCacheTimestamp ( String $timestamp ) : MinimeeService
setMaxCacheTimestamp ( craft\DateTime $lastTimeModified ) : MinimeeService
setPluginSettings ( $settings = [] ) : Void set plugin / config settings
setRuntimeSettings ( Array $settingsOverrides ) : MinimeeService Configure our service based off the settings in plugin, allowing plugin settings to be overridden at runtime.
setSettings ( craft\Minimee_ISettingsModel $settings ) : MinimeeService Manually pass in an instance of Minimee_ISettingsModel.
setType ( String $type ) : this
supportLegacyNamesAtRuntime ( Array $runtimeSettings = [] ) : Array Handle backwards-compat for 'cssTagTemplate' and 'jsTagTemplate' setting names.
supportLegacyNamesFromConfig ( Array $settings = [] ) : Array Handle backwards-compat for 'cssTagTemplate' and 'jsTagTemplate' setting names.

Method Details

abort() protected method

Internal function used when aborting due to error
protected abort ( String $e, String $level = LogLevel::Error ) : Bool
$e String
$level String
return Bool

appendToCacheBase() protected method

Append an asset's name to the cacheBase
protected appendToCacheBase ( String $name ) : Void
$name String
return Void

cacheExists() protected method

Checks if the cache exists.
protected cacheExists ( ) : Bool
return Bool

checkHeaders() protected method

Validate all assets prior to run.
protected checkHeaders ( ) : this
return this

createCache() protected method

Creates cache of assets.
protected createCache ( ) : boolean
return boolean

deleteExpiredCache() public method

Based on the cache's hashed base, attempts to delete any older versions of same name.
public deleteExpiredCache ( ) : void
return void

ensureCacheExists() protected method

Fetch or creates cache.
protected ensureCacheExists ( ) : MinimeeService
return MinimeeService

flightcheck() protected method

Perform pre-flight checks to ensure we can run.
protected flightcheck ( ) : this
return this

getAssets() protected method

protected getAssets ( ) : Array
return Array

getCacheBase() protected method

protected getCacheBase ( ) : string
return string

getCacheTimestamp() protected method

protected getCacheTimestamp ( ) : String
return String

getPluginSettings() protected method

get our plugin / config settings
protected getPluginSettings ( ) : Array
return Array

getSettings() protected method

protected getSettings ( ) : Minimee_SettingsModel
return Minimee_SettingsModel

getType() protected method

protected getType ( ) : String
return String

init() public method

During startup, fetch settings from our plugin / config
public init ( ) : void
return void

initPluginSettings() protected method

Fetch settings from our plugin / config
protected initPluginSettings ( ) : Void
return Void

isCombineEnabled() protected method

Return whether we should combine our cache or not
protected isCombineEnabled ( ) : boolean | null
return boolean | null

isUrl() protected method

Determine if string is valid URL
protected isUrl ( $string ) : boolean
return boolean TRUE if yes, FALSE if no

makeCacheFilename() protected method

If a "Resource" cache, format is: hashOfCacheBase.type e.g. asdf1234.css Otherwise, format is: hashOfCacheBase.timestamp.type e.g. asdf1234.12345678.css
protected makeCacheFilename ( ) : String
return String

makeHashOfCacheBase() protected method

protected makeHashOfCacheBase ( ) : String
return String

makePathToCacheFilename() protected method

protected makePathToCacheFilename ( ) : String
return String

makePathToHashOfCacheBase() protected method

protected makePathToHashOfCacheBase ( ) : String
return String

makePathToStorageFolder() public method

public makePathToStorageFolder ( ) : String
return String

makeReturn() protected method

protected makeReturn ( ) : String
return String

makeTagsByType() public method

Generate the HTML tag based on type
public makeTagsByType ( String $type, Array $assets = [] ) : String
$type String
$assets Array
return String

makeTwigMarkupFromHtml() public method

Wrapper for how we must return a twig option rather than raw HTML
public makeTwigMarkupFromHtml ( $html ) : Twig_Markup
return Twig_Markup

makeUrlToCacheFilename() protected method

protected makeUrlToCacheFilename ( ) : String
return String

minifyAsset() protected method

Given an asset, fetches and returns minified contents.
protected minifyAsset ( Minimee_BaseAssetModel $asset ) : String
$asset Minimee_BaseAssetModel
return String

minifyCssAsset() protected method

Method to (maybe) minify CSS asset
protected minifyCssAsset ( Minimee_BaseAssetModel $asset ) : String
$asset Minimee_BaseAssetModel
return String

minifyJsAsset() protected method

Method to (maybe) minify JS asset
protected minifyJsAsset ( Minimee_BaseAssetModel $asset ) : String
$asset Minimee_BaseAssetModel
return String

onCreateCache() protected method

Raise our 'onCreateCache' event
protected onCreateCache ( $event ) : Void
return Void

reset() protected method

Safely resets service to prepare for a clean run.
protected reset ( ) : this
return this

run() public method

Main service function that encapsulates an entire Minimee run
public run ( String $type, Array $assets, Array $settings = [] ) : Array | Bool
$type String
$assets Array
$settings Array
return Array | Bool

setAssets() protected method

protected setAssets ( Array $assets ) : this
$assets Array
return this

setCacheBase() protected method

protected setCacheBase ( String $name ) : MinimeeService
$name String
return MinimeeService

setCacheTimestamp() protected method

protected setCacheTimestamp ( String $timestamp ) : MinimeeService
$timestamp String
return MinimeeService

setMaxCacheTimestamp() protected method

protected setMaxCacheTimestamp ( craft\DateTime $lastTimeModified ) : MinimeeService
$lastTimeModified craft\DateTime
return MinimeeService

setPluginSettings() protected method

set plugin / config settings
protected setPluginSettings ( $settings = [] ) : Void
return Void

setRuntimeSettings() protected method

Configure our service based off the settings in plugin, allowing plugin settings to be overridden at runtime.
protected setRuntimeSettings ( Array $settingsOverrides ) : MinimeeService
$settingsOverrides Array
return MinimeeService

setSettings() protected method

Manually pass in an instance of Minimee_ISettingsModel.
protected setSettings ( craft\Minimee_ISettingsModel $settings ) : MinimeeService
$settings craft\Minimee_ISettingsModel
return MinimeeService

setType() protected method

protected setType ( String $type ) : this
$type String
return this

supportLegacyNamesAtRuntime() protected method

Remove in 1.x release!
protected supportLegacyNamesAtRuntime ( Array $runtimeSettings = [] ) : Array
$runtimeSettings Array
return Array

supportLegacyNamesFromConfig() protected method

Remove in 1.x release!
protected supportLegacyNamesFromConfig ( Array $settings = [] ) : Array
$settings Array
return Array

Property Details

$_assets protected_oe property

the trigger we use for our own resources
protected $_assets

$_cacheBase protected_oe property

css or js
protected $_cacheBase

$_cacheTimestamp protected_oe property

a concat of all asset filenames together
protected $_cacheTimestamp

$_deprecatedSettingsMap protected_oe property

static array of settings, a merge of DB and filesystem settings
protected $_deprecatedSettingsMap

$_pluginSettings protected_oe static_oe property

instance of Minimee_SettingsModel
protected static $_pluginSettings

$_settings protected_oe property

max timestamp of all assets
protected $_settings

$_type protected_oe property

array of Minimee_AssetModelInterface
protected $_type