Skip to content

Commit

Permalink
Added Template::____call() for BC
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Oct 11, 2014
1 parent f314671 commit 20625fb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Bridges/ApplicationLatte/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ public function getParameters()
}


/**
* @deprecated
*/
public function __call($name, $args)
{
trigger_error('Invoking filters on Template object outside of template file is deprecated, use your filter directly.', E_USER_DEPRECATED);
return $this->latte->invokeFilter($name, $args);
}


/**
* Sets a template parameter. Do not call directly.
* @return void
Expand Down
42 changes: 42 additions & 0 deletions tests/Application.Latte/Template.filters.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* Test: Template filters
*/

use Nette\Bridges\ApplicationLatte\Template,
Tester\Assert;


require __DIR__ . '/../bootstrap.php';


class LatteFactory implements Nette\Bridges\ApplicationLatte\ILatteFactory
{
private $engine;

public function __construct(Latte\Engine $engine)
{
$this->engine = $engine;
}

public function create()
{
return $this->engine;
}
}

$engine = new \Latte\Engine();
$template = new Template($engine);

Assert::exception(function () use ($template) {
@$template->length('abc');
}, 'LogicException', "Filter 'length' is not defined.");

$engine->addFilter('length', 'strlen');

Assert::same( 3, @$template->length('abc') );

Assert::error(function () use ($template) {
$template->length('abc');
}, E_USER_DEPRECATED, 'Invoking filters on Template object outside of template file is deprecated, use your filter directly.');

0 comments on commit 20625fb

Please sign in to comment.