<?php
+use MediaWiki\MediaWikiServices;
+
/**
* Handles compiling Mustache templates into PHP rendering functions
*
/**
* @param string $templateDir
- * @param boolean $forceRecompile
+ * @param bool $forceRecompile
*/
public function __construct( $templateDir = null, $forceRecompile = false ) {
$this->templateDir = $templateDir ?: __DIR__ . '/templates';
$fastHash = md5( $fileContents );
// Fetch a secret key for building a keyed hash of the PHP code
- $config = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
+ $config = MediaWikiServices::getInstance()->getMainConfig();
$secretKey = $config->get( 'SecretKey' );
if ( $secretKey ) {
// See if the compiled PHP code is stored in cache.
- $cache = ObjectCache::newAccelerator( CACHE_ANYTHING );
+ $cache = ObjectCache::getLocalServerInstance( CACHE_ANYTHING );
$key = $cache->makeKey( 'template', $templateName, $fastHash );
$code = $this->forceRecompile ? null : $cache->get( $key );
}
return LightnCandy::compile(
$code,
- array(
+ [
// Do not add more flags here without discussion.
// If you do add more flags, be sure to update unit tests as well.
'flags' => LightnCandy::FLAG_ERROR_EXCEPTION,
'basedir' => $this->templateDir,
'fileext' => '.mustache',
- )
+ ]
);
}
* @code
* echo $templateParser->processTemplate(
* 'ExampleTemplate',
- * array(
+ * [
* 'username' => $user->getName(),
* 'message' => 'Hello!'
- * )
+ * ]
* );
* @endcode
* @param string $templateName The name of the template
* @param array $scopes
* @return string
*/
- public function processTemplate( $templateName, $args, array $scopes = array() ) {
+ public function processTemplate( $templateName, $args, array $scopes = [] ) {
$template = $this->getTemplate( $templateName );
return call_user_func( $template, $args, $scopes );
}