Nette 2.4 – pouziti filtru – incompatible content type

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
DavidTheNewbie
Člen | 79
+
0
-

V novem Nette se mi generuje velky pocet warning hlasek:

PHP User Warning: Filter |trim is called with incompatible content type HTML, try to prepend |stripHtml. in …

Rad bych pouzil filtr trim, anebo jakykoliv jiny vlastni, ale Debugbar rika, abych pred nej vlozil stripHtml filtr, coz ale nechci, ponevadz chci HTML tagy zachovat. Jak tedy tento warning odstranit?

David Grudl
Nette Core | 8110
+
0
-

Pro trim by se HTML obsah asi dal povolit.

DavidTheNewbie
Člen | 79
+
0
-

David Grudl napsal(a):

Pro trim by se HTML obsah asi dal povolit.

A jak se warningu zbavit pri vytvoreni vlastniho filtru? Konkretne mam:

	/**
	 * @param  string UTF-8 encoding or 8-bit
	 * @return string
	 */
	public static function parse($s)
	{
		return Strings::replace(
			$s,
			'#(</textarea|</pre|</script|^).*?(?=<textarea|<pre|<script|\z)#si',
			function ($m) {
				return trim(preg_replace('~>\s+<~m', '><', $m[0]));
			}
		);
	}

…coz mi generuje warning viz vyse. Jak by se cistou cestou dalo warningu predejit?

Editoval DavidTheNewbie (10. 4. 2017 7:52)

galab
Backer | 74
+
0
-

Třeba takhle?

function ($m) {
    return new \Latte\Runtime\Html(trim(preg_replace('~>\s+<~m', '><', $m[0])));
}
David Grudl
Nette Core | 8110
+
+1
-

Taky se dá použít místo |trim filtr |strip

DavidTheNewbie
Člen | 79
+
0
-

galab napsal(a):

Třeba takhle?

function ($m) {
    return new \Latte\Runtime\Html(trim(preg_replace('~>\s+<~m', '><', $m[0])));
}

Toto bohuzel warning nepotlacilo. I pres tuto upravu stale generuje warning:

PHP User Warning: Filter |mycustomfilter is called with incompatible content type HTML, try to prepend |stripHtml. in

Editoval DavidTheNewbie (12. 4. 2017 22:16)

DavidTheNewbie
Člen | 79
+
0
-

David Grudl napsal(a):

Taky se dá použít místo |trim filtr |strip

strip namisto trim warning odstranilo. Diky. Warning vsak pretrvava pri pouziti vlastniho filtru, jehoz kod jsem uvedl viz vyse.

David Grudl
Nette Core | 8110
+
+2
-

Změň function myfilter($s) na function myfilter(Latte\Runtime\FilterInfo $info, $s)

DavidTheNewbie
Člen | 79
+
0
-

David Grudl napsal(a):

Změň function myfilter($s) na function myfilter(Latte\Runtime\FilterInfo $info, $s)

To jsem jiz zkusil a fungovalo, avsak code quality sniffer hlasil, ze mam ve funkci unused parameter, coz je pravda, jelikoz $info nikde v tele funkce nepouziju. Samozrejme lze toto hlaseni code snifferu potlacit, ale to se nezda byt uplne koser. Neslo by to „cisteji“? Anebo je to ciste a na podobne code quality sniffer programy moc nedbat?

Editoval DavidTheNewbie (12. 4. 2017 22:38)