1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-20 03:31:10 +01:00

Have AphrontView implement PhutilSafeHTMLProducerInterface

Summary: Allows views to work like tags.

Test Plan: Implemented a few completely arbitrary render() / singleView simplifications. I just picked some that were easy to test. I'll do a more thorough pass on this in a followup; these calls don't really hurt anything.

Reviewers: chad, vrana

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D5306
This commit is contained in:
epriestley 2013-03-09 13:52:21 -08:00
parent 25738e78a1
commit 5e41ead7c7
6 changed files with 32 additions and 22 deletions

View file

@ -1652,7 +1652,11 @@ phutil_register_library_map(array(
'AphrontTokenizerTemplateView' => 'AphrontView',
'AphrontTypeaheadTemplateView' => 'AphrontView',
'AphrontUsageException' => 'AphrontException',
'AphrontView' => 'Phobject',
'AphrontView' =>
array(
0 => 'Phobject',
1 => 'PhutilSafeHTMLProducerInterface',
),
'AphrontWebpageResponse' => 'AphrontHTMLResponse',
'AuditPeopleMenuEventListener' => 'PhutilEventListener',
'CelerityPhabricatorResourceController' => 'CelerityResourceController',

View file

@ -54,7 +54,7 @@ final class PhabricatorCalendarBrowseController
$nav->appendChild(
array(
$this->getNoticeView(),
hsprintf('<div style="padding: 20px;">%s</div>', $month_view->render()),
hsprintf('<div style="padding: 20px;">%s</div>', $month_view),
));
return $this->buildApplicationPage(

View file

@ -55,11 +55,10 @@ final class DifferentialInlineCommentEditView extends AphrontView {
'method' => 'POST',
'sigil' => 'inline-edit-form',
),
$this->renderSingleView(
array(
$this->renderInputs(),
$this->renderBody(),
)));
array(
$this->renderInputs(),
$this->renderBody(),
));
return hsprintf(
'<table>'.
@ -130,12 +129,11 @@ final class DifferentialInlineCommentEditView extends AphrontView {
array(
'class' => 'differential-inline-comment-edit-buttons',
),
$this->renderSingleView(
array(
$formatting,
$buttons,
phutil_tag('div', array('style' => 'clear: both'), ''),
)));
array(
$formatting,
$buttons,
phutil_tag('div', array('style' => 'clear: both'), ''),
));
return javelin_tag(
'div',
@ -148,12 +146,11 @@ final class DifferentialInlineCommentEditView extends AphrontView {
'length' => $this->length,
),
),
$this->renderSingleView(
array(
$title,
$body,
$edit,
)));
array(
$title,
$body,
$edit,
));
}
}

View file

@ -20,6 +20,7 @@ from XSS and render correctly. Broadly:
- Combine elements with arrays, not string concatenation.
- @{class:AphrontView} subclasses should return a
@{class@libphutil:PhutilSafeHTML} object from their `render()` method.
- @{class:AphrontView} subclasses act like tags when rendering.
- @{function:pht} has some special rules.
- There are some other things that you should be aware of.
- Do not use @{function:phutil_render_tag} or @{function:javelin_render_tag},
@ -124,6 +125,10 @@ return `phutil_tag()` or `javelin_tag()`:
return phutil_tag('div', ...);
You can use an @{class:AphrontView} subclass like you would a tag:
phutil_tag('div', array(), $view);
= Internationalization: pht() =
The @{function:pht} function has some special rules. If any input to

View file

@ -1,6 +1,7 @@
<?php
abstract class AphrontView extends Phobject {
abstract class AphrontView extends Phobject
implements PhutilSafeHTMLProducerInterface {
protected $user;
protected $children = array();
@ -65,4 +66,8 @@ abstract class AphrontView extends Phobject {
abstract public function render();
public function producePhutilSafeHTML() {
return $this->render();
}
}

View file

@ -145,8 +145,7 @@ final class PhabricatorPropertyListView extends AphrontView {
$shortcuts = null;
if ($this->hasKeyboardShortcuts) {
$shortcuts =
id(new AphrontKeyboardShortcutsAvailableView())->render();
$shortcuts = new AphrontKeyboardShortcutsAvailableView();
}
return array(