Phalcon assets NOTE
All classes are prefixed with Phalcon
Assets\Asset Source on GitHub
Namespace
Uses
Extends
Implements
Represents an asset
$asset = new \Phalcon\Assets\Asset ( "js" , "js/jquery.js" );
Properties /**
* @var array
*/
protected $attributes ;
/**
* @var bool
*/
protected $isAutoVersion = false ;
/**
* @var bool
*/
protected $filter ;
/**
* @var bool
*/
protected $isLocal ;
/**
* @var string
*/
protected $path ;
/**
* @var string
*/
protected $sourcePath ;
/**
* @var string
*/
protected $targetPath ;
/**
* @var string
*/
protected $targetUri ;
/**
* @var string
*/
protected $type ;
/**
* Version of resource
*
* @var string|null
*/
protected $version ;
Methods
public function __construct ( string $type , string $path , bool $isLocal = bool , bool $filter = bool , array $attributes = [], string $version = null , bool $isAutoVersion = bool );
Asset constructor.
public function getAssetKey () : string ;
Gets the asset's key.
public function getAttributes () : array ;
Gets extra HTML attributes.
public function getContent ( string $basePath = null ) : string ;
Returns the content of the asset as an string Optionally a base path where the asset is located can be set public function getFilter () : bool ;
public function getPath () : string ;
public function getRealSourcePath ( string $basePath = null ) : string ;
Returns the complete location where the asset is located
public function getRealTargetPath ( string $basePath = null ) : string ;
Returns the complete location where the asset must be written
public function getRealTargetUri () : string ;
Returns the real target uri for the generated HTML public function getSourcePath () : string ;
public function getTargetPath () : string ;
public function getTargetUri () : string ;
public function getType () : string ;
public function getVersion () : string | null ;
Version of resource
public function isAutoVersion () : bool ;
Checks if the asset is using auto version
public function isLocal () : bool ;
Checks if the asset is local or not
public function setAttributes ( array $attributes ) : AssetInterface ;
Sets extra HTML attributes public function setAutoVersion ( bool $flag ) : AssetInterface ;
public function setFilter ( bool $filter ) : AssetInterface ;
Sets if the asset must be filtered or not
public function setIsLocal ( bool $flag ) : AssetInterface ;
Sets if the asset is local or external
public function setPath ( string $path ) : AssetInterface ;
Sets the asset's path
public function setSourcePath ( string $sourcePath ) : AssetInterface ;
Sets the asset's source path
public function setTargetPath ( string $targetPath ) : AssetInterface ;
Sets the asset's target path
public function setTargetUri ( string $targetUri ) : AssetInterface ;
Sets a target uri for the generated HTML
public function setType ( string $type ) : AssetInterface ;
Sets the asset's type
public function setVersion ( string $version ) : AssetInterface ;
Sets the asset's version
protected function phpFileExists ( string $filename ) : bool ;
@todo to be removed when we get traits protected function phpFileGetContents ( string $filename );
Assets\Asset\Css Source on GitHub
Namespace
Uses
Extends
AssetBase
Implements
Represents CSS assets
Methods
public function __construct ( string $path , bool $local = bool , bool $filter = bool , array $attributes = [], string $version = null , bool $autoVersion = bool );
Phalcon\Assets\Asset\Css constructor Assets\Asset\Js Source on GitHub
Namespace
Uses
Extends
AssetBase
Implements
Represents JavaScript assets
Methods
public function __construct ( string $path , bool $local = bool , bool $filter = bool , array $attributes = [], string $version = null , bool $autoVersion = bool );
Phalcon\Assets\Asset\Js constructor Assets\AssetInterface Source on GitHub
Namespace
Uses
Extends
Implements
Interface for custom Phalcon\Assets resources
Methods
public function getAssetKey () : string ;
Gets the asset's key.
public function getAttributes () : array | null ;
Gets extra HTML attributes.
public function getFilter () : bool ;
Gets if the asset must be filtered or not.
public function getType () : string ;
Gets the asset's type.
public function setAttributes ( array $attributes ) : AssetInterface ;
Sets extra HTML attributes.
public function setFilter ( bool $filter ) : AssetInterface ;
Sets if the asset must be filtered or not.
public function setType ( string $type ) : AssetInterface ;
Sets the asset's type. Assets\Collection Source on GitHub
Namespace
Uses
ArrayIterator
Countable
IteratorAggregate
Extends
Implements
Countable
IteratorAggregate
Collection of asset objects
Properties /**
* @var array
*/
protected $assets ;
/**
* @var array
*/
protected $attributes ;
/**
* Should version be determined from file modification time
*
* @var bool
*/
protected $autoVersion = false ;
/**
* @var array
*/
protected $codes ;
/**
* @var array
*/
protected $filters ;
/**
* @var bool
*/
protected $isLocal = true ;
/**
* @var bool
*/
protected $join = true ;
/**
* @var string
*/
protected $prefix = ;
/**
* @var string
*/
protected $sourcePath = ;
/**
* @var bool
*/
protected $targetIsLocal = true ;
/**
* @var string
*/
protected $targetPath = ;
/**
* @var string
*/
protected $targetUri = ;
/**
* @var string
*/
protected $version = ;
Methods
public function add ( AssetInterface $asset ) : Collection ;
Adds an asset to the collection
public function addCss ( string $path , mixed $isLocal = null , bool $filter = bool , array $attributes = [], string $version = null , bool $autoVersion = bool ) : Collection ;
Adds a CSS asset to the collection
public function addFilter ( FilterInterface $filter ) : Collection ;
Adds a filter to the collection
public function addInline ( Inline $code ) : Collection ;
Adds an inline code to the collection
public function addInlineCss ( string $content , bool $filter = bool , array $attributes = [] ) : Collection ;
Adds an inline CSS to the collection
public function addInlineJs ( string $content , bool $filter = bool , array $attributes = [] ) : Collection ;
Adds an inline JavaScript to the collection
public function addJs ( string $path , mixed $isLocal = null , bool $filter = bool , array $attributes = [], string $version = null , bool $autoVersion = bool ) : Collection ;
Adds a JavaScript asset to the collection
public function count () : int ;
Return the count of the assets public function getAssets () : array ;
public function getAttributes () : array ;
public function getCodes () : array ;
public function getFilters () : array ;
public function getIterator () : \Traversable ;
Returns the generator of the class @link https://php.net/manual/en/iteratoraggregate.getiterator.php
public function getJoin () : bool ;
public function getPrefix () : string ;
public function getRealTargetPath ( string $basePath ) : string ;
Returns the complete location where the joined/filtered collection must be written public function getSourcePath () : string ;
public function getTargetIsLocal () : bool ;
public function getTargetPath () : string ;
public function getTargetUri () : string ;
public function getVersion () : string ;
public function has ( AssetInterface $asset ) : bool ;
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
public function isAutoVersion () : bool ;
Checks if collection is using auto version public function isLocal () : bool ;
public function join ( bool $flag ) : Collection ;
Sets if all filtered assets in the collection must be joined in a single result file
public function setAttributes ( array $attributes ) : Collection ;
Sets extra HTML attributes public function setAutoVersion ( bool $flag ) : Collection ;
public function setFilters ( array $filters ) : Collection ;
Sets an array of filters in the collection
public function setIsLocal ( bool $flag ) : Collection ;
Sets if the collection uses local assets by default
public function setPrefix ( string $prefix ) : Collection ;
Sets a common prefix for all the assets
public function setSourcePath ( string $sourcePath ) : Collection ;
Sets a base source path for all the assets in this collection
public function setTargetIsLocal ( bool $flag ) : Collection ;
Sets if the target local or not
public function setTargetPath ( string $targetPath ) : Collection ;
Sets the target path of the file for the filtered/join output
public function setTargetUri ( string $targetUri ) : Collection ;
Sets a target uri for the generated HTML
public function setVersion ( string $version ) : Collection ;
Sets the version
final protected function addAsset ( AssetInterface $asset ) : bool ;
Adds an asset or inline-code to the collection Assets\Exception Source on GitHub
Namespace
Uses
Extends
\Exception
Implements
Exceptions thrown in Phalcon\Assets will use this class
Assets\FilterInterface Source on GitHub
Namespace
Uses
Extends
Implements
Interface for custom Phalcon\Assets filters
Methods
public function filter ( string $content ) : string ;
Filters the content returning a string with the filtered content Assets\Filters\Cssmin Source on GitHub
Namespace
Uses
Phalcon\Assets\FilterInterface
Extends
Implements
Minify the CSS - removes comments removes newlines and line feeds keeping removes last semicolon from last property
Methods
public function filter ( string $content ) : string ;
Filters the content using CSSMIN NOTE: This functionality is not currently available
Assets\Filters\Jsmin Source on GitHub
Namespace
Uses
Phalcon\Assets\FilterInterface
Extends
Implements
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.
Methods
public function filter ( string $content ) : string ;
Filters the content using JSMIN NOTE: This functionality is not currently available
Assets\Filters\None Source on GitHub
Namespace
Uses
Phalcon\Assets\FilterInterface
Extends
Implements
Returns the content without make any modification to the original source
Methods
public function filter ( string $content ) : string ;
Returns the content as is Assets\Inline Source on GitHub
Namespace
Uses
Extends
Implements
Represents an inline asset
$inline = new \Phalcon\Assets\Inline ( "js" , "alert('hello world');" );
Properties /**
* @var array
*/
protected $attributes ;
/**
* @var string
*/
protected $content ;
/**
* @var bool
*/
protected $filter ;
/**
* @var string
*/
protected $type ;
Methods
public function __construct ( string $type , string $content , bool $filter = bool , array $attributes = [] );
Phalcon\Assets\Inline constructor
public function getAssetKey () : string ;
Gets the asset's key. public function getAttributes () : array ;
public function getContent () : string ;
public function getFilter () : bool ;
public function getType () : string ;
public function setAttributes ( array $attributes ) : AssetInterface ;
Sets extra HTML attributes
public function setFilter ( bool $filter ) : AssetInterface ;
Sets if the asset must be filtered or not
public function setType ( string $type ) : AssetInterface ;
Sets the inline's type Assets\Inline\Css Source on GitHub
Namespace
Uses
Extends
InlineBase
Implements
Represents an inlined CSS
Methods
public function __construct ( string $content , bool $filter = bool , array $attributes = [] );
Phalcon\Assets\Inline\Css constructor Assets\Inline\Js Source on GitHub
Namespace
Uses
Extends
InlineBase
Implements
Represents an inline JavaScript
Methods
public function __construct ( string $content , bool $filter = bool , array $attributes = [] );
Phalcon\Assets\Inline\Js constructor Assets\Manager Source on GitHub
Namespace
Uses
Phalcon\Assets\Asset\Css
Phalcon\Assets\Asset\Js
Phalcon\Assets\Inline\Css
Phalcon\Assets\Inline\Js
Phalcon\Di\AbstractInjectionAware
Phalcon\Html\Helper\Element
Phalcon\Html\Helper\Link
Phalcon\Html\Helper\Script
Phalcon\Html\TagFactory
Extends
AbstractInjectionAware
Implements
Manages collections of CSS/JavaScript assets
Properties /**
* @var array
*/
protected $collections ;
/**
* @var bool
*/
protected $implicitOutput = true ;
/**
* @var array
*/
protected $options ;
/**
* @var TagFactory
*/
protected $tagFactory ;
Methods
public function __construct ( TagFactory $tagFactory , array $options = [] );
Manager constructor.
public function addAsset ( Asset $asset ) : Manager ;
Adds a raw asset to the manager
public function addAssetByType ( string $type , Asset $asset ) : Manager ;
Adds a asset by its type
public function addCss ( string $path , bool $local = bool , bool $filter = bool , array $attributes = [], string $version = null , bool $autoVersion = bool ) : Manager ;
Adds a CSS asset to the 'css' collection
public function addInlineCode ( Inline $code ) : Manager ;
Adds a raw inline code to the manager
public function addInlineCodeByType ( string $type , Inline $code ) : Manager ;
Adds an inline code by its type
public function addInlineCss ( string $content , bool $filter = bool , array $attributes = [] ) : Manager ;
Adds an inline CSS to the 'css' collection
public function addInlineJs ( string $content , bool $filter = bool , array $attributes = [] ) : Manager ;
Adds an inline JavaScript to the 'js' collection
public function addJs ( string $path , bool $local = bool , bool $filter = bool , array $attributes = [], string $version = null , bool $autoVersion = bool ) : Manager ;
Adds a JavaScript asset to the 'js' collection $assets -> addJs ( "scripts/jquery.js" );
$assets -> addJs ( "http://jquery.my-cdn.com/jquery.js" , false );
public function collection ( string $name ) : Collection ;
Creates/Returns a collection of assets
public function collectionAssetsByType ( array $assets , string $type ) : array ;
Creates/Returns a collection of assets by type
public function exists ( string $name ) : bool ;
Returns true or false if collection exists. if ( $manager -> exists ( "jsHeader" )) {
// \Phalcon\Assets\Collection
$collection = $manager -> get ( "jsHeader" );
}
public function get ( string $name ) : Collection ;
Returns a collection by its id. $scripts = $assets -> get ( "js" );
public function getCollections () : Collection [];
Returns existing collections in the manager
public function getCss () : Collection ;
Returns the CSS collection of assets
public function getJs () : Collection ;
Returns the CSS collection of assets
public function getOptions () : array ;
Returns the manager options
public function has ( string $name ) : bool ;
Returns true or false if collection exists. if ( $manager -> has ( "jsHeader" )) {
// \Phalcon\Assets\Collection
$collection = $manager -> get ( "jsHeader" );
}
public function output ( Collection $collection , string $type ) : string | null ;
Traverses a collection calling the callback to generate its HTML
public function outputCss ( string $name = null ) : string ;
Prints the HTML for CSS assets
public function outputInline ( Collection $collection , mixed $type ) : string ;
Traverses a collection and generate its HTML
public function outputInlineCss ( string $name = null ) : string ;
Prints the HTML for inline CSS
public function outputInlineJs ( string $name = null ) : string ;
Prints the HTML for inline JS
public function outputJs ( string $name = null ) : string ;
Prints the HTML for JS assets
public function set ( string $name , Collection $collection ) : Manager ;
Sets a collection in the Assets Manager $assets -> set ( "js" , $collection );
public function setOptions ( array $options ) : Manager ;
Sets the manager options
public function useImplicitOutput ( bool $implicitOutput ) : Manager ;
Sets if the HTML generated must be directly printed or returned