Skip to content

Commit

Permalink
API Deprecate API which is moving into its own module (#11454)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Nov 5, 2024
1 parent d110c9e commit d871f40
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 40 deletions.
8 changes: 8 additions & 0 deletions src/View/SSTemplateParseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace SilverStripe\View;

use Exception;
use SilverStripe\Dev\Deprecation;

/**
* This is the exception raised when failing to parse a template. Note that we don't currently do any static analysis,
* so we can't know if the template will run, just if it's malformed. It also won't catch mistakes that still look
* valid.
*
* @deprecated 5.4.0 Will be renamed to SilverStripe\TemplateEngine\Exception\SSTemplateParseException
*/
class SSTemplateParseException extends Exception
{
Expand All @@ -19,6 +22,11 @@ class SSTemplateParseException extends Exception
*/
public function __construct($message, $parser)
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be renamed to SilverStripe\TemplateEngine\Exception\SSTemplateParseException',
Deprecation::SCOPE_CLASS
);
$prior = substr($parser->string ?? '', 0, $parser->pos);

preg_match_all('/\r\n|\r|\n/', $prior ?? '', $matches);
Expand Down
8 changes: 8 additions & 0 deletions src/View/SSTemplateParser.peg
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace SilverStripe\View;
use SilverStripe\Core\Injector\Injector;
use Parser;
use InvalidArgumentException;
use SilverStripe\Dev\Deprecation;

// We want this to work when run by hand too
if (defined('THIRDPARTY_PATH')) {
Expand Down Expand Up @@ -72,6 +73,8 @@ if (defined('THIRDPARTY_PATH')) {
*
* Angle Bracket: angle brackets "<" and ">" are used to eat whitespace between template elements
* N: eats white space including newlines (using in legacy _t support)
*
* @deprecated 5.4.0 Will be renamed to SilverStripe\TemplateEngine\SSTemplateParser
*/
class SSTemplateParser extends Parser implements TemplateParser
{
Expand Down Expand Up @@ -119,6 +122,11 @@ class SSTemplateParser extends Parser implements TemplateParser
*/
function construct($matchrule, $name, $arguments = null)
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be renamed to SilverStripe\TemplateEngine\SSTemplateParser',
Deprecation::SCOPE_CLASS
);
$res = parent::construct($matchrule, $name, $arguments);
if (!isset($res['php'])) {
$res['php'] = '';
Expand Down
8 changes: 8 additions & 0 deletions src/View/SSTemplateParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\Core\Injector\Injector;
use Parser;
use InvalidArgumentException;
use SilverStripe\Dev\Deprecation;

// We want this to work when run by hand too
if (defined('THIRDPARTY_PATH')) {
Expand Down Expand Up @@ -51,6 +52,8 @@
*
* Angle Bracket: angle brackets "<" and ">" are used to eat whitespace between template elements
* N: eats white space including newlines (using in legacy _t support)
*
* @deprecated 5.4.0 Will be renamed to SilverStripe\TemplateEngine\SSTemplateParser
*/
class SSTemplateParser extends Parser implements TemplateParser
{
Expand Down Expand Up @@ -98,6 +101,11 @@ public function __construct($closedBlocks = [], $openBlocks = [])
*/
function construct($matchrule, $name, $arguments = null)
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be renamed to SilverStripe\TemplateEngine\SSTemplateParser',
Deprecation::SCOPE_CLASS
);
$res = parent::construct($matchrule, $name, $arguments);
if (!isset($res['php'])) {
$res['php'] = '';
Expand Down
74 changes: 37 additions & 37 deletions src/View/SSViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class SSViewer implements Flushable
*
* @config
* @var string
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine.global_key
* @deprecated 5.4.0 Will be moved to SilverStripe\TemplateEngine\SSTemplateEngine.global_key
*/
private static $global_key = '$CurrentReadingMode, $CurrentUser.ID';

Expand Down Expand Up @@ -136,31 +136,31 @@ class SSViewer implements Flushable
* List of items being processed
*
* @var array
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
* @deprecated 5.4.0 Will be moved to SilverStripe\TemplateEngine\SSTemplateEngine
*/
protected static $topLevel = [];

/**
* List of templates to select from
*
* @var array
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
* @deprecated 5.4.0 Will be moved to SilverStripe\TemplateEngine\SSTemplateEngine
*/
protected $templates = null;

/**
* Absolute path to chosen template file
*
* @var string
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
* @deprecated 5.4.0 Will be moved to SilverStripe\TemplateEngine\SSTemplateEngine
*/
protected $chosen = null;

/**
* Templates to use when looking up 'Layout' or 'Content'
*
* @var array
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
* @deprecated 5.4.0 Will be moved to SilverStripe\TemplateEngine\SSTemplateEngine
*/
protected $subTemplates = [];

Expand All @@ -171,13 +171,13 @@ class SSViewer implements Flushable

/**
* @var TemplateParser
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
* @deprecated 5.4.0 Will be moved to SilverStripe\TemplateEngine\SSTemplateEngine
*/
protected $parser;

/**
* @var CacheInterface
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
* @deprecated 5.4.0 Will be moved to SilverStripe\TemplateEngine\SSTemplateEngine
*/
protected $partialCacheStore = null;

Expand Down Expand Up @@ -216,11 +216,11 @@ public function __construct($templates, TemplateParser $parser = null)

/**
* Triggered early in the request when someone requests a flush.
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::flush()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flush()
*/
public static function flush()
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::flush()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flush()');
SSViewer::flush_template_cache(true);
SSViewer::flush_cacheblock_cache(true);
}
Expand All @@ -231,11 +231,11 @@ public static function flush()
* @param string $content The template content
* @param bool|void $cacheTemplate Whether or not to cache the template from string
* @return SSViewer
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::renderString()
*/
public static function fromString($content, $cacheTemplate = null)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::renderString()');
$viewer = SSViewer_FromString::create($content);
if ($cacheTemplate !== null) {
$viewer->setCacheTemplate($cacheTemplate);
Expand Down Expand Up @@ -400,11 +400,11 @@ public static function setRewriteHashLinksDefault($rewrite)

/**
* @param string|array $templates
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setTemplate()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::setTemplate()
*/
public function setTemplate($templates)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setTemplate()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::setTemplate()');
$this->templates = $templates;
$this->chosen = $this->chooseTemplate($templates);
$this->subTemplates = [];
Expand All @@ -427,23 +427,23 @@ public static function chooseTemplate($templates)
* Set the template parser that will be used in template generation
*
* @param TemplateParser $parser
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setParser()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::setParser()
*/
public function setParser(TemplateParser $parser)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setParser()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::setParser()');
$this->parser = $parser;
}

/**
* Returns the parser that is set for template generation
*
* @return TemplateParser
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::getParser()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::getParser()
*/
public function getParser()
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getParser()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::getParser()');
if (!$this->parser) {
$this->setParser(Injector::inst()->get('SilverStripe\\View\\SSTemplateParser'));
}
Expand All @@ -456,11 +456,11 @@ public function getParser()
* @param array|string $templates
*
* @return bool
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::hasTemplate()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::hasTemplate()
*/
public static function hasTemplate($templates)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::hasTemplate()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::hasTemplate()');
return (bool)ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes());
}

Expand Down Expand Up @@ -504,11 +504,11 @@ public static function getTemplateFileByType($identifier, $type = null)
*
* @param bool $force Set this to true to force a re-flush. If left to false, flushing
* may only be performed once a request.
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::flushTemplateCache()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flushTemplateCache()
*/
public static function flush_template_cache($force = false)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::flushTemplateCache()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flushTemplateCache()');
if (!SSViewer::$template_cache_flushed || $force) {
$dir = dir(TEMP_PATH);
while (false !== ($file = $dir->read())) {
Expand All @@ -527,11 +527,11 @@ public static function flush_template_cache($force = false)
*
* @param bool $force Set this to true to force a re-flush. If left to false, flushing
* may only be performed once a request.
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::flushCacheBlockCache()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flushCacheBlockCache()
*/
public static function flush_cacheblock_cache($force = false)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::flushCacheBlockCache()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flushCacheBlockCache()');
if (!SSViewer::$cacheblock_cache_flushed || $force) {
$cache = Injector::inst()->get(CacheInterface::class . '.cacheblock');
$cache->clear();
Expand All @@ -545,23 +545,23 @@ public static function flush_cacheblock_cache($force = false)
* Set the cache object to use when storing / retrieving partial cache blocks.
*
* @param CacheInterface $cache
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setPartialCacheStore()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::setPartialCacheStore()
*/
public function setPartialCacheStore($cache)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setPartialCacheStore()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::setPartialCacheStore()');
$this->partialCacheStore = $cache;
}

/**
* Get the cache object to use when storing / retrieving partial cache blocks.
*
* @return CacheInterface
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::getPartialCacheStore()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::getPartialCacheStore()
*/
public function getPartialCacheStore()
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getPartialCacheStore()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::getPartialCacheStore()');
if ($this->partialCacheStore) {
return $this->partialCacheStore;
}
Expand Down Expand Up @@ -591,11 +591,11 @@ public function includeRequirements($incl = true)
* @param array $underlay Any variables to layer underneath the scope
* @param SSViewer_Scope|null $inheritedScope The current scope of a parent template including a sub-template
* @return string The result of executing the template
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::includeGeneratedTemplate()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::includeGeneratedTemplate()
*/
protected function includeGeneratedTemplate($cacheFile, $item, $overlay, $underlay, $inheritedScope = null)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::includeGeneratedTemplate()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::includeGeneratedTemplate()');
if (isset($_GET['showtemplate']) && $_GET['showtemplate'] && Permission::check('ADMIN')) {
$lines = file($cacheFile ?? '');
echo "<h2>Template: $cacheFile</h2>";
Expand Down Expand Up @@ -724,11 +724,11 @@ public function process($item, $arguments = null, $inheritedScope = null)
* @param string $subtemplate Sub-template to use
*
* @return array|null
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::getSubtemplateFor()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::getSubtemplateFor()
*/
protected function getSubtemplateFor($subtemplate)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getSubtemplateFor()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::getSubtemplateFor()');
// Get explicit subtemplate name
if (isset($this->subTemplates[$subtemplate])) {
return $this->subTemplates[$subtemplate];
Expand Down Expand Up @@ -766,13 +766,13 @@ function ($template) {
* @param bool $globalRequirements
*
* @return string Evaluated result
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::execute_template()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::execute_template()
*/
public static function execute_template($template, $data, $arguments = null, $scope = null, $globalRequirements = false)
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be replaced with SilverStripe\View\SSTemplateEngine::execute_template()'
'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::execute_template()'
);
$v = SSViewer::create($template);

Expand Down Expand Up @@ -803,11 +803,11 @@ public static function execute_template($template, $data, $arguments = null, $sc
* @param bool $globalRequirements
*
* @return string Evaluated result
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::renderString()
*/
public static function execute_string($content, $data, $arguments = null, $globalRequirements = false)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::renderString()');
$v = SSViewer::fromString($content);

if ($globalRequirements) {
Expand All @@ -832,11 +832,11 @@ public static function execute_string($content, $data, $arguments = null, $globa
* @param string $content The template contents
* @param string $template The template file name
* @return string
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::parseTemplateContent()
* @deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::parseTemplateContent()
*/
public function parseTemplateContent($content, $template = "")
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::parseTemplateContent()');
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::parseTemplateContent()');
return $this->getParser()->compileString(
$content,
$template,
Expand Down
13 changes: 13 additions & 0 deletions src/View/SSViewer_BasicIteratorSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace SilverStripe\View;

use SilverStripe\Dev\Deprecation;

/**
* Defines an extra set of basic methods that can be used in templates
* that are not defined on sub-classes of {@link ViewableData}.
*
* @deprecated 5.4.0 Will be renamed to SilverStripe\TemplateEngine\BasicIteratorSupport
*/
class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider
{
Expand All @@ -18,6 +22,15 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider
*/
protected $iteratorTotalItems;

public function __construct()
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be renamed to SilverStripe\TemplateEngine\BasicIteratorSupport',
Deprecation::SCOPE_CLASS
);
}

/**
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion src/View/SSViewer_DataPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* data that is scope-independant (like BaseURL), or type-specific data that is layered on top cross-cut like
* (like $FirstLast etc).
*
* @deprecated 5.4.0 Will be merged into SilverStripe\View\SSViewer_Scope
* @deprecated 5.4.0 Will be merged into SilverStripe\TemplateEngine\ScopeManager
*/
class SSViewer_DataPresenter extends SSViewer_Scope
{
Expand Down
Loading

0 comments on commit d871f40

Please sign in to comment.