Skip to content

Override default classes

Junaid Atari edited this page Aug 24, 2016 · 5 revisions

Info: This tutorial will demonstrate how to override default yii2cdn core classes.

Default core classes (in \yii2cdn\Cdn)

Component class

  • Cdn property: $componentClass
  • Default class: \yii2cdn\Component
/** @var \yii2cdn\Component $component */
$component = \Yii::$app->cdn->get('component-id');

Component's section class

  • Cdn property: $sectionClass
  • Default class: \yii2cdn\Section
/** @var \yii2cdn\Section $section */
$section = $component->getSection('section-id');

Component section's File class

  • Cdn property: $fileClass
  • Default class: \yii2cdn\File
/** @var \yii2cdn\File $file */
$file = $section->getFile('file-id');

CDN Configuration parser class

  • Cdn property: $configParserClass
  • Default class: \yii2cdn\ConfigParser

CDN Configuration File Class

  • Cdn property: $configFileClass
  • Default class: \yii2cdn\ConfigFile

CDN configuration loader class

  • Cdn property: $configLoaderClass
  • Default class: \yii2cdn\ConfigLoader

Extandable Class

  1. Create a file Component.php under /common/yii2cdn/ directrory
  2. Add the following code:
namespace common/yii2cdn;

class Component extends \yii2cdn\Component {
 // Add your logic, override methods here...
}

Setup in main.php File


  1. Open @app/config/main.php in your code editor.
  2. Add a new propery componentClass inside the cdn component like the following example:
// ...
'components' => [
	// ...
	'cdn' => [
		'class' => '\yii2cdn\Cdn',
        // Extended CDN component class
		'componentClass' => '\common\yii2cdn\Component',
        // ...
	],
  // ...
],
// ...

Note: the red links below are pages yet to be created. Feel free to add them!

Overview documents

  • README: distributed with yii2cdn, contains a quick overview of yii2cdn's functionality, an example, and the license.
  • REFERENCE: Containing incomplete api class reference.

Quick Start

Configuration

Tutorials

Clone this wiki locally