Phalcon assets
NOTE
All classes are prefixed with Phalcon
Assets\Asset¶
Class Source on GitHub
Object representation of an asset
Phalcon\Assets\Asset- implementsPhalcon\Assets\AssetInterface
Uses Phalcon\Assets\Exceptions\CannotReadAsset · Phalcon\Assets\Traits\AttributesTrait · Phalcon\Assets\Traits\SourceTargetTrait · Phalcon\Traits\Php\FileTrait · Phalcon\Traits\Php\HashTrait
Method Summary¶
public
__construct(string $type,string $path,bool $isLocal = true,bool $filter = true,array $attributes = [],string|null $version = null,bool $isAutoVersion = false)
Asset constructor.
public
string
getAssetKey()
Gets the asset's key.
public
array
getAttributes()
Gets extra HTML attributes.
public
string
getContent( string|null $basePath = null )
Returns the content of the asset as an string
public
bool
getFilter()
Gets if the asset must be filtered or not.
public
string
getPath()
Returns the path for this asset
public
string
getRealSourcePath( string|null $basePath = null )
Returns the complete location where the asset is located
public
string
getRealTargetPath( string|null $basePath = null )
Returns the complete location where the asset must be written
public
string
getRealTargetUri()
Returns the real target uri for the generated HTML
public
string
getType()
Gets the asset's type.
public
string|null
getVersion()
Gets the asset's version.
public
bool
isAutoVersion()
Checks if the asset is using auto version
public
AssetInterface
setAttributes( array $attributes )
Sets extra HTML attributes
public
AssetInterface
setAutoVersion( bool $flag )
public
AssetInterface
setFilter( bool $filter )
Sets if the asset must be filtered or not
public
AssetInterface
setPath( string $path )
Sets the asset's path
public
AssetInterface
setType( string $type )
Sets the asset's type
public
AssetInterface
setVersion( string $version )
Sets the asset's version
Properties¶
protected
bool
$filter = true
protected
bool
$isAutoVersion = false
protected
string
$path
protected
string
$type
protected
string|null
$version = null
Methods¶
__construct()¶
public function __construct(
string $type,
string $path,
bool $isLocal = true,
bool $filter = true,
array $attributes = [],
string|null $version = null,
bool $isAutoVersion = false
);
Asset constructor.
getAssetKey()¶
Gets the asset's key.
getAttributes()¶
Gets extra HTML attributes.
getContent()¶
Returns the content of the asset as an string Optionally a base path where the asset is located can be set
getFilter()¶
Gets if the asset must be filtered or not.
getPath()¶
Returns the path for this asset
getRealSourcePath()¶
Returns the complete location where the asset is located
getRealTargetPath()¶
Returns the complete location where the asset must be written
getRealTargetUri()¶
Returns the real target uri for the generated HTML
getType()¶
Gets the asset's type.
getVersion()¶
Gets the asset's version.
isAutoVersion()¶
Checks if the asset is using auto version
setAttributes()¶
Sets extra HTML attributes
setAutoVersion()¶
setFilter()¶
Sets if the asset must be filtered or not
setPath()¶
Sets the asset's path
setType()¶
Sets the asset's type
setVersion()¶
Sets the asset's version
Assets\AssetInterface¶
Interface Source on GitHub
Phalcon\Assets\AssetInterface
Phalcon\Contracts\Assets\AssetPhalcon\Assets\AssetInterface
Uses Phalcon\Contracts\Assets\Asset
Assets\Asset\Css¶
Class Source on GitHub
Represents CSS assets
Phalcon\Assets\AssetPhalcon\Assets\Asset\Css
Uses Phalcon\Assets\Asset
Method Summary¶
Methods¶
__construct()¶
public function __construct(
string $path,
bool $local = true,
bool $filter = true,
array $attributes = [],
string|null $version = null,
bool $autoVersion = false
);
Css constructor.
Assets\Asset\Js¶
Class Source on GitHub
Represents JavaScript assets
Phalcon\Assets\AssetPhalcon\Assets\Asset\Js
Uses Phalcon\Assets\Asset
Method Summary¶
Methods¶
__construct()¶
public function __construct(
string $path,
bool $local = true,
bool $filter = true,
array $attributes = [],
string|null $version = null,
bool $autoVersion = false
);
Js constructor.
Assets\Collection¶
Class Source on GitHub
Collection of asset objects
@template TKey of array-key
@template TValue of AssetInterface
@implements IteratorAggregate
Phalcon\Assets\Collection- implements\Countable,\IteratorAggregate
Uses ArrayIterator · Countable · IteratorAggregate · Phalcon\Assets\Traits\AttributesTrait · Phalcon\Assets\Traits\SourceTargetTrait · Phalcon\Traits\Php\FileTrait · Traversable
Method Summary¶
public
static
add( AssetInterface $asset )
Adds an asset to the collection
public
static
addCss(string $path,bool|null $isLocal = null,bool $filter = true,array $attributes = [],string|null $version = null,bool $autoVersion = false)
Adds a CSS asset to the collection
public
static
addFilter( FilterInterface $filter )
Adds a filter to the collection
public
static
addInline( Inline $code )
Adds an inline code to the collection
public
static
addInlineCss(string $content,bool $filter = true,array $attributes = [])
Adds an inline CSS to the collection
public
static
addInlineJs(string $content,bool $filter = true,array $attributes = [])
Adds an inline JavaScript to the collection
public
static
addJs(string $path,bool|null $isLocal = null,bool $filter = true,array $attributes = [],string|null $version = null,bool $autoVersion = false)
Adds a JavaScript asset to the collection
public
int
count()
Return the count of the assets
public
array
getAssets()
Return the stored assets
public
array
getCodes()
Return the stored codes
public
array
getFilters()
Return the stored filters
public
Traversable
getIterator()
Returns the iterator of the class
public
bool
getJoin()
public
string
getPrefix()
Returns the prefix
public
string
getRealTargetPath( string $basePath )
Returns the complete location where the joined/filtered collection must
public
bool
getTargetIsLocal()
Returns whether the target is local or not
public
string
getVersion()
Returns the version
public
bool
has( AssetInterface $asset )
Checks this the asset is added to the collection.
public
bool
isAutoVersion()
Checks if collection is using auto version
public
static
join( bool $flag )
Sets if all filtered assets in the collection must be joined in a single
public
static
setAttributes( array $attributes )
Sets extra HTML attributes
public
static
setAutoVersion( bool $flag )
public
static
setFilters( array $filters )
Sets an array of filters in the collection
public
static
setPrefix( string $prefix )
Sets a common prefix for all the assets
public
static
setTargetIsLocal( bool $flag )
Sets if the target local or not
public
static
setVersion( string $version )
Sets the version
protected
bool
addAsset( AssetInterface $asset )
Adds an asset or inline-code to the collection
Properties¶
protected
array<string, AssetInterface>
$assets = []
protected
bool
$autoVersion = false
Should version be determined from file modification time
protected
AssetInterface[]
$codes = []
protected
FilterInterface[]
$filters = []
protected
bool
$join = true
protected
string
$prefix = ""
protected
bool
$targetIsLocal = true
protected
string
$version = ""
Methods¶
add()¶
Adds an asset to the collection
addCss()¶
public function addCss(
string $path,
bool|null $isLocal = null,
bool $filter = true,
array $attributes = [],
string|null $version = null,
bool $autoVersion = false
): static;
Adds a CSS asset to the collection
addFilter()¶
Adds a filter to the collection
addInline()¶
Adds an inline code to the collection
addInlineCss()¶
public function addInlineCss(
string $content,
bool $filter = true,
array $attributes = []
): static;
Adds an inline CSS to the collection
addInlineJs()¶
public function addInlineJs(
string $content,
bool $filter = true,
array $attributes = []
): static;
Adds an inline JavaScript to the collection
addJs()¶
public function addJs(
string $path,
bool|null $isLocal = null,
bool $filter = true,
array $attributes = [],
string|null $version = null,
bool $autoVersion = false
): static;
Adds a JavaScript asset to the collection
count()¶
Return the count of the assets
@link https://php.net/manual/en/countable.count.php
getAssets()¶
Return the stored assets
getCodes()¶
Return the stored codes
getFilters()¶
Return the stored filters
getIterator()¶
Returns the iterator of the class
getJoin()¶
getPrefix()¶
Returns the prefix
getRealTargetPath()¶
Returns the complete location where the joined/filtered collection must be written
getTargetIsLocal()¶
Returns whether the target is local or not
getVersion()¶
Returns the version
has()¶
Checks this the asset is added to the collection.
use Phalcon\Assets\Asset;
use Phalcon\Assets\Collection;
$collection = new Collection();
$asset = new Asset("js", "js/jquery.js");
$collection->add($asset);
$collection->has($asset); // true
isAutoVersion()¶
Checks if collection is using auto version
join()¶
Sets if all filtered assets in the collection must be joined in a single result file
setAttributes()¶
Sets extra HTML attributes
setAutoVersion()¶
setFilters()¶
Sets an array of filters in the collection
setPrefix()¶
Sets a common prefix for all the assets
setTargetIsLocal()¶
Sets if the target local or not
setVersion()¶
Sets the version
addAsset()¶
Adds an asset or inline-code to the collection
Assets\Exception¶
Class Source on GitHub
Exceptions thrown in Phalcon\Assets will use this class
\ExceptionPhalcon\Assets\ExceptionPhalcon\Assets\Exceptions\AssetSourceTargetCollisionPhalcon\Assets\Exceptions\CannotReadAssetPhalcon\Assets\Exceptions\CollectionNotFoundPhalcon\Assets\Exceptions\InvalidAssetSourcePathPhalcon\Assets\Exceptions\InvalidAssetTargetPathPhalcon\Assets\Exceptions\InvalidFilterPhalcon\Assets\Exceptions\InvalidTargetPathPhalcon\Assets\Exceptions\TargetPathIsDirectory
Assets\Exceptions\AssetSourceTargetCollision¶
Class Source on GitHub
\ExceptionPhalcon\Assets\ExceptionPhalcon\Assets\Exceptions\AssetSourceTargetCollision
Uses Phalcon\Assets\Exception
Method Summary¶
Methods¶
__construct()¶
Assets\Exceptions\CannotReadAsset¶
Class Source on GitHub
\ExceptionPhalcon\Assets\ExceptionPhalcon\Assets\Exceptions\CannotReadAsset
Uses Phalcon\Assets\Exception
Method Summary¶
Methods¶
__construct()¶
Assets\Exceptions\CollectionNotFound¶
Class Source on GitHub
\ExceptionPhalcon\Assets\ExceptionPhalcon\Assets\Exceptions\CollectionNotFound
Uses Phalcon\Assets\Exception
Method Summary¶
Methods¶
__construct()¶
Assets\Exceptions\InvalidAssetSourcePath¶
Class Source on GitHub
\ExceptionPhalcon\Assets\ExceptionPhalcon\Assets\Exceptions\InvalidAssetSourcePath
Uses Phalcon\Assets\Exception
Method Summary¶
Methods¶
__construct()¶
Assets\Exceptions\InvalidAssetTargetPath¶
Class Source on GitHub
\ExceptionPhalcon\Assets\ExceptionPhalcon\Assets\Exceptions\InvalidAssetTargetPath
Uses Phalcon\Assets\Exception
Method Summary¶
Methods¶
__construct()¶
Assets\Exceptions\InvalidFilter¶
Class Source on GitHub
\ExceptionPhalcon\Assets\ExceptionPhalcon\Assets\Exceptions\InvalidFilter
Uses Phalcon\Assets\Exception
Method Summary¶
Methods¶
__construct()¶
Assets\Exceptions\InvalidTargetPath¶
Class Source on GitHub
\ExceptionPhalcon\Assets\ExceptionPhalcon\Assets\Exceptions\InvalidTargetPath
Uses Phalcon\Assets\Exception
Method Summary¶
Methods¶
__construct()¶
Assets\Exceptions\TargetPathIsDirectory¶
Class Source on GitHub
\ExceptionPhalcon\Assets\ExceptionPhalcon\Assets\Exceptions\TargetPathIsDirectory
Uses Phalcon\Assets\Exception
Method Summary¶
Methods¶
__construct()¶
Assets\FilterInterface¶
Interface Source on GitHub
Phalcon\Assets\FilterInterface
Phalcon\Contracts\Assets\FilterPhalcon\Assets\FilterInterface
Uses Phalcon\Contracts\Assets\Filter
Assets\Filters\CssMin¶
Class Source on GitHub
Minify the CSS - removes comments removes newlines and line feeds keeping removes last semicolon from last property
Phalcon\Assets\Filters\CssMin- implementsPhalcon\Assets\FilterInterface
Uses MatthiasMullie\Minify\CSS · Phalcon\Assets\FilterInterface
Method Summary¶
Methods¶
filter()¶
Filters the content using CSSMIN
Assets\Filters\JsMin¶
Class Source on GitHub
Deletes the characters which are insignificant to JavaScript. Comments will be removed. Tabs will be replaced with spaces. Carriage returns will be replaced with linefeeds. Most spaces and linefeeds will be removed.
Phalcon\Assets\Filters\JsMin- implementsPhalcon\Assets\FilterInterface
Uses MatthiasMullie\Minify\JS · Phalcon\Assets\FilterInterface
Method Summary¶
Methods¶
filter()¶
Filters the content using JSMIN
Assets\Filters\None¶
Class Source on GitHub
Returns the content without make any modification to the original source
Phalcon\Assets\Filters\None- implementsPhalcon\Assets\FilterInterface
Uses Phalcon\Assets\FilterInterface
Method Summary¶
Methods¶
filter()¶
Returns the content as is
Assets\Inline¶
Class Source on GitHub
Represents an inline asset
Phalcon\Assets\Inline- implementsPhalcon\Assets\AssetInterface
Uses Phalcon\Assets\Traits\AttributesTrait · Phalcon\Traits\Php\HashTrait
Method Summary¶
public
__construct(string $type,string $content,bool $filter = true,array $attributes = [])
Inline constructor.
public
string
getAssetKey()
Gets the asset's key.
public
array
getAttributes()
Gets extra HTML attributes.
public
string
getContent()
Gets if the asset content
public
bool
getFilter()
Gets if the asset must be filtered or not.
public
string
getType()
Gets the asset's type.
public
AssetInterface
setAttributes( array $attributes )
Sets extra HTML attributes
public
AssetInterface
setFilter( bool $filter )
Sets if the asset must be filtered or not
public
AssetInterface
setType( string $type )
Sets the inline's type
Properties¶
protected
string
$content
protected
bool
$filter = true
protected
string
$type
Methods¶
__construct()¶
public function __construct(
string $type,
string $content,
bool $filter = true,
array $attributes = []
);
Inline constructor.
getAssetKey()¶
Gets the asset's key.
getAttributes()¶
Gets extra HTML attributes.
getContent()¶
Gets if the asset content
getFilter()¶
Gets if the asset must be filtered or not.
getType()¶
Gets the asset's type.
setAttributes()¶
Sets extra HTML attributes
setFilter()¶
Sets if the asset must be filtered or not
setType()¶
Sets the inline's type
Assets\Inline\Css¶
Class Source on GitHub
Represents an inlined CSS
Phalcon\Assets\InlinePhalcon\Assets\Inline\Css
Uses Phalcon\Assets\Inline
Method Summary¶
Methods¶
__construct()¶
Css constructor.
Assets\Inline\Js¶
Class Source on GitHub
Represents an inline JavaScript
Phalcon\Assets\InlinePhalcon\Assets\Inline\Js
Uses Phalcon\Assets\Inline
Method Summary¶
Methods¶
__construct()¶
Js constructor.
Assets\Manager¶
Class Source on GitHub
Manages collections of CSS/JavaScript assets
Phalcon\Assets\Manager- implementsPhalcon\Di\InjectionAwareInterface
Uses Exception · Phalcon\Assets\Asset\Css · Phalcon\Assets\Asset\Js · Phalcon\Assets\Exceptions\AssetSourceTargetCollision · Phalcon\Assets\Exceptions\CollectionNotFound · Phalcon\Assets\Exceptions\InvalidAssetSourcePath · Phalcon\Assets\Exceptions\InvalidAssetTargetPath · Phalcon\Assets\Exceptions\InvalidFilter · Phalcon\Assets\Exceptions\InvalidTargetPath · Phalcon\Assets\Exceptions\TargetPathIsDirectory · Phalcon\Assets\Inline\Css · Phalcon\Assets\Inline\Js · Phalcon\Di\InjectionAwareInterface · Phalcon\Di\Traits\InjectionAwareTrait · Phalcon\Html\Helper\Link · Phalcon\Html\Helper\Script · Phalcon\Html\TagFactory · Phalcon\Traits\Php\FileTrait
Method Summary¶
public
__construct(TagFactory $tagFactory,array $options = [])
Manager constructor.
public
static
addAsset( Asset $asset )
Adds a raw asset to the manager
public
static
addAssetByType(string $type,Asset $asset)
Adds an asset by its type
public
static
addCss(string $path,bool $local = true,bool $filter = true,array $attributes = [],string|null $version = null,bool $autoVersion = false)
Adds a CSS asset to the 'css' collection
public
static
addInlineCode( Inline $code )
Adds a raw inline code to the manager
public
static
addInlineCodeByType(string $type,Inline $code)
Adds an inline code by its type
public
static
addInlineCss(string $content,bool $filter = true,array $attributes = [])
Adds an inline CSS to the 'css' collection
public
static
addInlineJs(string $content,bool $filter = true,array $attributes = [])
Adds an inline JavaScript to the 'js' collection
public
static
addJs(string $path,bool $local = true,bool $filter = true,array $attributes = [],string|null $version = null,bool $autoVersion = false)
Adds a JavaScript asset to the 'js' collection
public
Collection
collection( string $name )
Creates/Returns a collection of assets
public
array
collectionAssetsByType(array $assets,string $type)
Creates/Returns a collection of assets by type
public
bool
exists( string $name )
Returns true or false if collection exists.
public
Collection
get( string $name )
Returns a collection by its id.
public
array
getCollections()
Returns existing collections in the manager
public
Collection
getCss()
Returns the CSS collection of assets
public
Collection
getJs()
Returns the CSS collection of assets
public
array
getOptions()
Returns the manager options
public
bool
has( string $name )
Returns true or false if collection exists.
public
string|null
output(Collection $collection,string $type)
Traverses a collection calling the callback to generate its HTML
public
string
outputCss( string|null $name = null )
Prints the HTML for CSS assets
public
string
outputInline(Collection $collection,string $type)
Traverses a collection and generate its HTML
public
string
outputInlineCss( string|null $name = null )
Prints the HTML for inline CSS
public
string
outputInlineJs( string|null $name = null )
Prints the HTML for inline JS
public
string
outputJs( string|null $name = null )
Prints the HTML for JS assets
public
static
set(string $name,Collection $collection)
Sets a collection in the Assets Manager
public
static
setOptions( array $options )
Sets the manager options
public
static
useImplicitOutput( bool $implicitOutput )
Sets if the HTML generated must be directly printed or returned
Properties¶
protected
array<string, Collection>
$collections = []
protected
bool
$implicitOutput = true
protected
array
$options = []
protected
TagFactory
$tagFactory
Methods¶
__construct()¶
Manager constructor.
addAsset()¶
Adds a raw asset to the manager
addAssetByType()¶
Adds an asset by its type
addCss()¶
public function addCss(
string $path,
bool $local = true,
bool $filter = true,
array $attributes = [],
string|null $version = null,
bool $autoVersion = false
): static;
Adds a CSS asset to the 'css' collection
addInlineCode()¶
Adds a raw inline code to the manager
addInlineCodeByType()¶
Adds an inline code by its type
addInlineCss()¶
public function addInlineCss(
string $content,
bool $filter = true,
array $attributes = []
): static;
Adds an inline CSS to the 'css' collection
addInlineJs()¶
public function addInlineJs(
string $content,
bool $filter = true,
array $attributes = []
): static;
Adds an inline JavaScript to the 'js' collection
addJs()¶
public function addJs(
string $path,
bool $local = true,
bool $filter = true,
array $attributes = [],
string|null $version = null,
bool $autoVersion = false
): static;
Adds a JavaScript asset to the 'js' collection
collection()¶
Creates/Returns a collection of assets
collectionAssetsByType()¶
Creates/Returns a collection of assets by type
exists()¶
Returns true or false if collection exists.
if ($manager->exists("jsHeader")) {
// \Phalcon\Assets\Collection
$collection = $manager->get("jsHeader");
}
get()¶
Returns a collection by its id.
getCollections()¶
Returns existing collections in the manager
getCss()¶
Returns the CSS collection of assets
getJs()¶
Returns the CSS collection of assets
getOptions()¶
Returns the manager options
has()¶
Returns true or false if collection exists.
if ($manager->has("jsHeader")) {
// \Phalcon\Assets\Collection
$collection = $manager->get("jsHeader");
}
output()¶
Traverses a collection calling the callback to generate its HTML
outputCss()¶
Prints the HTML for CSS assets
outputInline()¶
Traverses a collection and generate its HTML
outputInlineCss()¶
Prints the HTML for inline CSS
outputInlineJs()¶
Prints the HTML for inline JS
outputJs()¶
Prints the HTML for JS assets
set()¶
Sets a collection in the Assets Manager
setOptions()¶
Sets the manager options
useImplicitOutput()¶
Sets if the HTML generated must be directly printed or returned
Assets\Traits\AttributesTrait¶
Trait Source on GitHub
Shared HTML-attributes state for asset objects (Asset, Inline,
Collection).
@todo v7 - share setAttributes here too (blocked: Collection is not an AssetInterface, so the return type diverges)
Phalcon\Assets\Traits\AttributesTrait
Used by Phalcon\Assets\Asset · Phalcon\Assets\Collection · Phalcon\Assets\Inline
Method Summary¶
Properties¶
protected
array<string, string>
$attributes = []
Methods¶
getAttributes()¶
Gets extra HTML attributes.
Assets\Traits\SourceTargetTrait¶
Trait Source on GitHub
Shared source/target path, uri and locality state for asset objects
(Asset, Collection).
Phalcon\Assets\Traits\SourceTargetTrait
Used by Phalcon\Assets\Asset · Phalcon\Assets\Collection
Method Summary¶
public
string
getSourcePath()
public
string
getTargetPath()
public
string
getTargetUri()
public
bool
isLocal()
Checks if the asset is local or not
public
static
setIsLocal( bool $flag )
Sets if the asset is local or external
public
static
setSourcePath( string $sourcePath )
Sets the asset's source path
public
static
setTargetPath( string $targetPath )
Sets the asset's target path
public
static
setTargetUri( string $targetUri )
Sets a target uri for the generated HTML
Properties¶
protected
bool
$isLocal = true
protected
string
$sourcePath = ""
protected
string
$targetPath = ""
protected
string
$targetUri = ""
Methods¶
getSourcePath()¶
getTargetPath()¶
getTargetUri()¶
isLocal()¶
Checks if the asset is local or not
setIsLocal()¶
Sets if the asset is local or external
setSourcePath()¶
Sets the asset's source path
setTargetPath()¶
Sets the asset's target path
setTargetUri()¶
Sets a target uri for the generated HTML