Skip to content
Permalink
Browse files

Adding StringTemplateTrait so that the string template functionality …

…can be easy shared between helpers in preparation of refactoring the Form helper to use string templates as well.
  • Loading branch information...
burzum committed Dec 20, 2013
1 parent 6f012c8 commit 6e8752e0c8e4df95fba63b43a9cc055812d43f43
Showing with 59 additions and 14 deletions.
  1. +3 −14 Cake/View/Helper/PaginatorHelper.php
  2. +56 −0 Cake/View/Helper/StringTemplateTrait.php
@@ -16,7 +16,6 @@
use Cake\Utility\Inflector;
use Cake\View\Helper;
use Cake\View\StringTemplate;
use Cake\View\View;
/**
@@ -28,6 +27,8 @@
*/
class PaginatorHelper extends Helper {
use StringTemplateTrait;
/**
* Holds the default options for pagination links
*
@@ -44,13 +45,6 @@ class PaginatorHelper extends Helper {
*/
public $options = [];
/**
* StringTemplate instance.
*
* @var Cake\View\StringTemplate
*/
protected $_templater;
/**
* The default templates used by PaginatorHelper.
*
@@ -83,12 +77,7 @@ class PaginatorHelper extends Helper {
*/
public function __construct(View $View, $settings = []) {
parent::__construct($View, $settings);
$this->_templater = new StringTemplate();
$this->_templater->add($this->_defaultTemplates);
if (isset($settings['templates'])) {
$this->_templater->load($settings['templates']);
}
$this->_initStringTemplates($this->_defaultTemplates);
}
/**
@@ -0,0 +1,56 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 1.2.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\View\Helper;
use Cake\View\StringTemplate;
trait StringTemplateTrait {
/**
* StringTemplate instance.
*
* @var Cake\View\StringTemplate
*/
protected $_templater;
/**
* Initializes the StringTemplate class and loads templates
*
* @param array $templates
* @return void
*/
protected function _initStringTemplates($templates = []) {
$this->_templater = new StringTemplate();
$this->_templater->add($templates);
if (isset($this->settings['templates'])) {
$this->_templater->load($this->settings['templates']);
}
}
/**
* Get/set templates to use.
*
* @param string|null|array $templates null or string allow reading templates. An array
* allows templates to be added.
* @return void|string|array
*/
public function templates($templates = null) {
if ($templates === null || is_string($templates)) {
return $this->_templater->get($templates);
}
return $this->_templater->add($templates);
}
}

0 comments on commit 6e8752e

Please sign in to comment.
You can’t perform that action at this time.