Overview
  • Namespace
  • Class

Namespaces

  • yii2cdn

Classes

  • Cdn
  • Component
  • ConfigFile
  • ConfigLoader
  • ConfigParser
  • File
  • Section

Class Component

Yii2 CDN Component object

Namespace: yii2cdn
Package: yii2cdn
Author: Junaid Atari mj.atari@gmail.com
Version: 0.1
Located at src/Component.php

Methods summary

public
# __construct( array $config, array $config,… )

Component constructor.

Component constructor.

Parameters

$config
$id Component ID
$config,…
Configuration
protected
# buildSections( array $config )

Create the component section object from config
Note: Empty sections will be removed

Create the component section object from config
Note: Empty sections will be removed

Parameters

$config
Configuration object
public string|array
# getUrl( null|string|array $str = null )

Get the component's base Url

Get the component's base Url

Parameters

$str
(optional) Append string at end of url (/ is optional) | List of strings to append url with (default: null)

Returns

string|array
public array
# getJsFiles( boolean $asUrl = false, boolean $unique = true )

Get a javaScript files list

Get a javaScript files list

Parameters

$asUrl
(optional) True will return files url only (default: false)
$unique
(optional) True will remove duplicate elements (default: true)

Returns

array
List of js section files
public yii2cdn\Section|array|null
# getSection( string|array $name, boolean $throwException = true )

Get a section(s) object by ID

Get a section(s) object by ID

Parameters

$name
name|List of sections name
$throwException
(optional) True will throw exception when section name not found (default: true)

Returns

yii2cdn\Section|array|null
Section | Sections List | Null when not found

Throws

yii\base\InvalidParamException
When null given as section
yii\base\UnknownPropertyException
When section name not found
public True
# sectionExists( string $name, boolean $throwException = true )

Check that given section exists

Check that given section exists

Parameters

$name
Section name to check
$throwException
(optional) True will throw exception when section name not found (default: false)

Returns

True
on exist | False when not found

Throws

yii\base\InvalidValueException
When section name is empty
yii\base\UnknownPropertyException
When section name not found
public array
# getCssFiles( boolean $asUrl = true, boolean $unique = true )

Get style files list

Get style files list

Parameters

$asUrl
(optional) True will return files url only (default: false)
$unique
(optional) True will remove duplicate elements (default: true)

Returns

array
List of css section files
public
# register( array $cssOptions = [], array $jsOptions = [], callable $callback = null )

Register css and js files into current view

Register css and js files into current view

Parameters

$cssOptions
(optional) Optional pass to css files
$jsOptions
(optional) Optional pass to js files
$callback

(optional) Perform callback on each registering file

function ( string $fileUrl, string $fileId ) {
     // some logic here ...
   }

See

Component::registerCssFiles() for $cssOptions
Component::registerJsFiles() for $jsOptions
public
# registerCssFiles( array $options = [], callable $callback = null )

Register component CSS files

Register component CSS files

Parameters

$options

the HTML attributes for the link tag. Please refer to [[Html::cssFile()]] for the supported options. The following options are specially handled and are not treated as HTML attributes:

  • depends: array, specifies the names of the asset bundles that this CSS file depends on.
$callback

(optional) Perform callback on each registering file

function ( string &$fileUrl, string &$fileId ) {
     // some logic here ...
   }

See

yii2cdn\Section::registerFilesAs()
public
# registerJsFiles( array $options = [], callable $callback = null )

Register component JavaScript files

Register component JavaScript files

Parameters

$options

the HTML attributes for the script tag. The following options are specially handled and are not treated as HTML attributes:

  • depends: array, specifies the names of the asset bundles that this JS file depends on.
  • position: specifies where the JS script tag should be inserted in a page. The possible values are:
    • [[POS_HEAD]]: in the head section
    • [[POS_BEGIN]]: at the beginning of the body section
    • [[POS_END]]: at the end of the body section. This is the default value.

Please refer to [[Html::jsFile()]] for other supported options.

$callback

(optional) Perform callback on each registering file

function ( string &$fileUrl, string &$fileId ) {
     // some logic here ...
   }

See

yii2cdn\Section::registerFilesAs()
public yii2cdn\File|string|null
# getFileByRoot( string $root, boolean $asUrl = false, boolean $throwException = true )

Get the file by root Root example : section/file-id

Get the file by root Root example : section/file-id

Parameters

$root
Root to file
$asUrl
True will return file url instead of object (default: false)
$throwException
True will throw exception (default: true)

Returns

yii2cdn\File|string|null
Section file | File Url | Null when not found

Throws

yii\base\InvalidParamException
When null given as section
yii\base\UnknownPropertyException
When section name not found
yii\base\UnknownPropertyException
When file id not found

See

Section::getSection()
yii2cdn\Section::getFileById()

Properties summary

protected string $id

Component ID

Component ID

#
protected string $baseUrl

Component's base url

Component's base url

#
protected yii2cdn\Section[] $sections

Sections list

Sections list

# []
protected array $sectionsName

CDN sections name

CDN sections name

# []
API documentation generated by ApiGen