2016-12-27 14:58:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wikia\PortableInfobox\Helpers;
|
|
|
|
|
2018-07-24 13:56:43 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2018-08-08 09:31:33 +00:00
|
|
|
use Wikia\Template\TemplateEngine;
|
2016-12-27 14:58:01 +00:00
|
|
|
|
2018-08-08 09:31:33 +00:00
|
|
|
class PortableInfoboxTemplateEngine {
|
2016-12-27 14:58:01 +00:00
|
|
|
const TYPE_NOT_SUPPORTED_MESSAGE = 'portable-infobox-render-not-supported-type';
|
|
|
|
|
|
|
|
protected static $templates = [
|
2018-08-08 09:31:33 +00:00
|
|
|
'wrapper' => 'PortableInfoboxWrapper.hbs',
|
|
|
|
'title' => 'PortableInfoboxItemTitle.hbs',
|
|
|
|
'header' => 'PortableInfoboxItemHeader.hbs',
|
|
|
|
'image' => 'PortableInfoboxItemImage.hbs',
|
|
|
|
'data' => 'PortableInfoboxItemData.hbs',
|
|
|
|
'group' => 'PortableInfoboxItemGroup.hbs',
|
|
|
|
'smart-group' => 'PortableInfoboxItemSmartGroup.hbs',
|
|
|
|
'horizontal-group-content' => 'PortableInfoboxHorizontalGroupContent.hbs',
|
|
|
|
'navigation' => 'PortableInfoboxItemNavigation.hbs',
|
|
|
|
'image-collection' => 'PortableInfoboxItemImageCollection.hbs'
|
2016-12-27 14:58:01 +00:00
|
|
|
];
|
|
|
|
protected $templateEngine;
|
|
|
|
|
|
|
|
public function __construct() {
|
2018-08-08 09:31:33 +00:00
|
|
|
$this->templateEngine = ( new TemplateEngine )
|
2016-12-27 14:58:01 +00:00
|
|
|
->setPrefix( self::getTemplatesDir() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getTemplatesDir() {
|
|
|
|
return dirname( __FILE__ ) . '/../../templates';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getTemplates() {
|
|
|
|
return self::$templates;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render( $type, array $data ) {
|
|
|
|
return $this->templateEngine->clearData()
|
|
|
|
->setData( $data )
|
|
|
|
->render( self::getTemplates()[ $type ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* check if item type is supported and logs unsupported types
|
|
|
|
*
|
|
|
|
* @param string $type - template type
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isSupportedType( $type ) {
|
|
|
|
$result = isset( static::$templates[ $type ] );
|
|
|
|
if ( !$result ) {
|
2018-07-24 13:56:43 +00:00
|
|
|
LoggerFactory::getInstance( 'PortableInfobox' )->info( self::TYPE_NOT_SUPPORTED_MESSAGE, [ 'type' => $type ] );
|
2016-12-27 14:58:01 +00:00
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|