-
Notifications
You must be signed in to change notification settings - Fork 2
CDN Class
Junaid Atari edited this page Aug 25, 2016
·
4 revisions
/** @var \yii2cdn\Cdn $cdn */
$cdn = \Yii::$app->cdn;
Type: \yii2cdn\Component
Get a component by ID.
/** @var \yii2cdn\Component $component */
$component = $cdn->get('font-awesome');
Type: boolean
Check that component exists.
// false to disable throwing exception
var_dump( $cdn->exists('font-awesome', false) );
// Output: bool(true)
Type: string
| array
Get the url of CDN.
echo $cdn->getUrl();
// Output: /cdn
echo $cdn->getUrl('js/bundle.min.js');
// Output: /cdn/js/bundle.min.js
\yii\helpers\VarDumper::dump( $cdn->getUrl([
'bundles/all.min.js',
'bundles/all.min.css',
]), 10, true );
// Output:
/*
[
0 => '/cdn/bundle/all.min.js'
1 => '/cdn/bundle/all.min.css'
]
*/
Type: string
| array
Get the base path of CDN direcory.
echo $cdn->getPath();
// Output: /var/www/html/cdn
echo $cdn->getPath('js/bundle.min.js');
// Output: /var/www/html/cdn/js/bundle.min.js
\yii\helpers\VarDumper::dump( $cdn->getPath([
'bundles/all.min.js',
'bundles/all.min.css',
]), 10, true );
// Output:
/*
[
0 => '/var/www/html/cdn/bundle/all.min.js'
1 => '/var/www/html/cdn/bundle/all.min.css'
]
*/
Type: \yii2cdn\Section
Get a component section by root.
//root = component-id/section-id
/** @var \yii2cdn\Section $section */
$section = $cdn->getFileByRoot('font-awesome/css');
Type: \yii2cdn\File
| string
Get a component section's file by root.
//root = component-id/section-id/file-id
/** @var \yii2cdn\File $file */
$file = $cdn->getFileByRoot('font-awesome/css/core');
echo $cdn->getFileByRoot('font-awesome/css/core', true);
// Output: ../cdn/font-awesome/css/font-awesome.min.css
Type: void
Execute a callback function when CDN status is online.
/** Example 1: (online) */
if ( \yii2cdn\Cdn::isOnline() ) {
// some logic goes here
}
/** Example 2: (online event) */
\Yii::$app->cdn->whenOnline (function ($cdn) {
/** @var \yii2cdn\Cdn $cdn */
// some logic goes here
});
Type: void
Execute a callback function when CDN status is offline.
/** Example 1: (offline) */
if ( !\yii2cdn\Cdn::isOnline() ) {
// some logic goes here
}
/** Example 2: (offline event) */
\Yii::$app->cdn->whenOffline (function ($cdn) {
/** @var \yii2cdn\Cdn $cdn */
// some logic goes here
});
Type: void
Clears the cdn cache and repopulate components.
$cdn->refresh();
Copyright (c) 2016 Junaid Atari and it's contributes.