\Dewdrop\ViewView

A simple view implementation that allows for simple assignment of data, escaping for common contexts (e.g. HTML, HTML attribute, JS, etc.), and calling of helper objects for reusable view logic.

Including method annotations here (http://www.phpdoc.org/docs/latest/references/phpdoc/tags/method.html) to assist static analysis in PHPStorm and Scrutinizer CI given the use of the __call() magic method in this class for view helpers. Won't cover us on custom helpers necessarily, but it will help catch most bugs/typos.

Summary

Methods
Properties
Constants
__construct()
init()
assign()
assignInstance()
registerHelper()
__get()
__set()
__isset()
__call()
helper()
partial()
getRequest()
getEscaper()
setScriptPath()
render()
escapeHtml()
escapeHtmlAttr()
escapeJs()
encodeJsonHtmlSafe()
escapeUrl()
escapeCss()
adminComponentNav()
adminNotice()
adminUrl()
block()
bootstrapColumnsModal()
bootstrapDetailsView()
bootstrapFilterForm()
bootstrapForm()
bootstrapInputText()
bootstrapRowActions()
bootstrapSelect()
bootstrapTable()
bootstrapTextarea()
bowerUrl()
bulkActionForm()
bulkActionCheckboxField()
checkboxList()
csvCellRenderer()
csvExport()
detectEditHelper()
editForm()
editControlRenderer()
headLink()
headMeta()
headScript()
headStyle()
inlineScript()
inputCheckbox()
inputText()
inputTimestamp()
pagination()
select()
summernote()
table()
tableCellRenderer()
tableSortHandle()
textarea()
urlCachePrefix()
wpAdminNotice()
wpCheckboxList()
wpColorPicker()
wpEditForm()
wpEditor()
wpEditRow()
wpImagePicker()
wpInputCheckbox()
wpInputText()
wpSelect()
wpTable()
wpWrap()
wrap()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
instantiateHelper()
castEscaperStringValue()
$internalViewData
$helpers
$scriptPath
$request
$helperClasses
N/A

Properties

$internalViewData

$internalViewData : array

The data assigned to this view. Usually, a controller will be responsible for passing data to the view object using the assign() method.

Type

array

$helpers

$helpers : array

Helper instances created by calls to instantiateHelper().

Type

array

$scriptPath

$scriptPath : string

The path in which to look for view scripts.

Type

string

$request

$request : \Dewdrop\Request

The current HTTP request.

Type

\Dewdrop\Request

$helperClasses

$helperClasses : array

The available helper names and their associated classes.

Type

array

Methods

__construct()

__construct(\Zend\Escaper\Escaper  $escaper = null, \Dewdrop\Request  $request = null) 

Create a new view, optionally supplying an escaper object for use in sanitizing output in various contexts.

Parameters

\Zend\Escaper\Escaper $escaper
\Dewdrop\Request $request

init()

init() : void

This method can be used by sub-classes to setup additional helpers, etc.

assign()

assign(string|array  $name, mixed  $value = null) : \Dewdrop\View\View

Assign variables to this view's data.

If the $name parameter is an array rather than a string, assign() will iterate over it, assigning variables for each key-value pair. For example, passing the following array would assign 3 different data variables:

$this->assign( array( 'var1' => 1, 'var1' => 2, 'var1' => 3 ) );

Parameters

string|array $name
mixed $value

Returns

\Dewdrop\View\View

assignInstance()

assignInstance(string  $name, object  $instance) : $this

Assign a helper instance to the supplied name, rather than requiring that it be instantiated when the helper is accessed. Typically used to share helper instances with partials generated by a parent view, which reduces resource usage and allows things like CSS and JS added by partials to propagate intuitively.

Parameters

string $name
object $instance

Returns

$this

registerHelper()

registerHelper(string  $name, string  $className) : \Dewdrop\View\View

Register a new helper name and class name. This can be used to replace a default helper implementation or to introduce a project-specific helper.

Parameters

string $name
string $className

The full class name/namespace.

Returns

\Dewdrop\View\View

__get()

__get(string  $name) : mixed

Retrieve the named index from the $data property or return null. This makes it easier to avoid undefined variable notices in your view scripts because you don't have to be quite so circumspect in ensuring variables are set before checking them.

Parameters

string $name

Returns

mixed

__set()

__set(string  $name, mixed  $value) : \Dewdrop\View\View

Delegate assignment to unknown class properties to the assign() method.

Parameters

string $name
mixed $value

Returns

\Dewdrop\View\View

__isset()

__isset(string  $name) : boolean

Check to see if the given item is present in the view's data array.

Parameters

string $name

Returns

boolean

__call()

__call(string  $method, array  $args) : \Dewdrop\View\Helper\AbstractHelper

When calling an unknown method on this view, pass the method name to the helper() method and call the helper's direct() method. Using the __call() magic method in this way allows using helpers in this manner:

$this->helperName('arg1', $arg2);

Rather than having to call an additional method on the helper like this:

$this->helper('helperName')->direct('arg1', $arg2);

If the direct() method is unavailable, the helper instance is returned instead.

Parameters

string $method
array $args

Returns

\Dewdrop\View\Helper\AbstractHelper

helper()

helper(string  $name) : \Dewdrop\View\Helper\AbstractHelper

Get the helper matching the provided named.

Parameters

string $name

Throws

\Dewdrop\Exception

Returns

\Dewdrop\View\Helper\AbstractHelper

partial()

partial(string  $template, array  $data, string  $scriptPath = null) : string

Render a partial view. By default, the same script path used by this view is passed along. This escaper from this view is also passed to the partial.

Parameters

string $template
array $data
string $scriptPath

Returns

string

getRequest()

getRequest() : \Dewdrop\Request

Get the current Request object for access to GET or POST data from helpers.

Returns

\Dewdrop\Request

getEscaper()

getEscaper() : \Zend\Escaper\Escaper

The escaper is made accessible so that partial/nested views can reuse the escaper object rather than having to make another.

Returns

\Zend\Escaper\Escaper

setScriptPath()

setScriptPath(string  $path) : \Dewdrop\View\View

Set the path in which to look for view scripts.

Parameters

string $path

Returns

\Dewdrop\View\View

render()

render(string  $template) : string

Render the provided template file.

The file's name should end in .phtml and be present in the assigned script path. This method returns the output as a string so that you have the opportunity to filter or otherwise handle it prior to actually adding it to the response.

Parameters

string $template

Returns

string

escapeHtml()

escapeHtml(string  $string) : string

Escape string included in normal HTML context (i.e. not in an attribute value).

Parameters

string $string

Returns

string

escapeHtmlAttr()

escapeHtmlAttr(string  $string) : string

Escape a string included in an HTML attribute value.

Parameters

string $string

Returns

string

escapeJs()

escapeJs(string  $string) : string

Escape a JavaScript string.

Parameters

string $string

Returns

string

encodeJsonHtmlSafe()

encodeJsonHtmlSafe(mixed  $input) : string

This will encode the supplied input as JSON using flags that make it safe to embed that JSON in an HTML context like an inline script block.

Parameters

mixed $input

Returns

string

escapeUrl()

escapeUrl(string  $string) : string

Escape a URL.

Parameters

string $string

Returns

string

escapeCss()

escapeCss(string  $string) : string

Escape a CSS property value.

Parameters

string $string

Returns

string

adminComponentNav()

adminComponentNav() : string

Returns

string

adminNotice()

adminNotice() : string

Returns

string

adminUrl()

adminUrl() : string

Returns

string

block()

block(\=  $name) : \Dewdrop\View\Block|\Dewdrop\View\Helper\Block

Parameters

\= $name

Returns

\Dewdrop\View\Block|\Dewdrop\View\Helper\Block

bootstrapColumnsModal()

bootstrapColumnsModal() : string

Returns

string

bootstrapDetailsView()

bootstrapDetailsView() : string

Returns

string

bootstrapFilterForm()

bootstrapFilterForm() : mixed

Returns

mixed

bootstrapForm()

bootstrapForm() : mixed

Returns

mixed

bootstrapInputText()

bootstrapInputText() : string

Returns

string

bootstrapRowActions()

bootstrapRowActions() : \Dewdrop\View\Helper\BootstrapRowActions

Returns

\Dewdrop\View\Helper\BootstrapRowActions

bootstrapSelect()

bootstrapSelect() : string

Returns

string

bootstrapTable()

bootstrapTable() : mixed

Returns

mixed

bootstrapTextarea()

bootstrapTextarea() : string

Returns

string

bowerUrl()

bowerUrl(string  $url, string  $wwwPath = null, string  $docRoot = null) : string

Parameters

string $url
string $wwwPath
string $docRoot

Returns

string

bulkActionForm()

bulkActionForm() : \Dewdrop\View\Helper\BulkActionForm

Returns

\Dewdrop\View\Helper\BulkActionForm

bulkActionCheckboxField()

bulkActionCheckboxField(\BulkActions  $bulkActions, \TableCell  $tableCellRenderer) : \Dewdrop\View\Helper\BulkActionCheckboxField

Parameters

\BulkActions $bulkActions
\TableCell $tableCellRenderer

Returns

\Dewdrop\View\Helper\BulkActionCheckboxField

checkboxList()

checkboxList() : string

Returns

string

csvCellRenderer()

csvCellRenderer() : \Dewdrop\Fields\Helper\CsvCell

Returns

\Dewdrop\Fields\Helper\CsvCell

csvExport()

csvExport() : string

Returns

string

detectEditHelper()

detectEditHelper() : \Dewdrop\View\Helper\DetectEditHelper

Returns

\Dewdrop\View\Helper\DetectEditHelper

editForm()

editForm() : \Dewdrop\View\Helper\EditForm

Returns

\Dewdrop\View\Helper\EditForm

editControlRenderer()

editControlRenderer() : \Dewdrop\Fields\Helper\EditControl

Returns

\Dewdrop\Fields\Helper\EditControl

headLink()

headLink() : \Zend\View\Helper\HeadLink

Returns

\Zend\View\Helper\HeadLink

headMeta()

headMeta() : \Zend\View\Helper\HeadMeta

Returns

\Zend\View\Helper\HeadMeta

headScript()

headScript() : \Zend\View\Helper\HeadScript

Returns

\Zend\View\Helper\HeadScript

headStyle()

headStyle() : \Zend\View\Helper\HeadStyle

Returns

\Zend\View\Helper\HeadStyle

inlineScript()

inlineScript() : void

inputCheckbox()

inputCheckbox() : string

Returns

string

inputText()

inputText() : string

Returns

string

inputTimestamp()

inputTimestamp() : string

Returns

string

pagination()

pagination() : string

Returns

string

select()

select() : string

Returns

string

summernote()

summernote() : string

Returns

string

table()

table() : mixed

Returns

mixed

tableCellRenderer()

tableCellRenderer() : \Dewdrop\Fields\Helper\TableCell

Returns

\Dewdrop\Fields\Helper\TableCell

tableSortHandle()

tableSortHandle() : \Dewdrop\View\Helper\TableSortHandle

Returns

\Dewdrop\View\Helper\TableSortHandle

textarea()

textarea() : string

Returns

string

urlCachePrefix()

urlCachePrefix() : mixed

Returns

mixed

wpAdminNotice()

wpAdminNotice() : string

Returns

string

wpCheckboxList()

wpCheckboxList() : string

Returns

string

wpColorPicker()

wpColorPicker() : string

Returns

string

wpEditForm()

wpEditForm() : \Dewdrop\View\Helper\WpEditForm

Returns

\Dewdrop\View\Helper\WpEditForm

wpEditor()

wpEditor() : string

Returns

string

wpEditRow()

wpEditRow() : \Dewdrop\View\Helper\WpEditRow

Returns

\Dewdrop\View\Helper\WpEditRow

wpImagePicker()

wpImagePicker() : string

Returns

string

wpInputCheckbox()

wpInputCheckbox() : string

Returns

string

wpInputText()

wpInputText() : string

Returns

string

wpSelect()

wpSelect() : string

Returns

string

wpTable()

wpTable() : mixed

Returns

mixed

wpWrap()

wpWrap() : \Dewdrop\View\Helper\WpWrap

Returns

\Dewdrop\View\Helper\WpWrap

wrap()

wrap() : \Dewdrop\View\Helper\Wrap

Returns

\Dewdrop\View\Helper\Wrap

instantiateHelper()

instantiateHelper(string  $name) : \Dewdrop\View\Helper\AbstractHelper

Create an instance of helper associated with the provided name and store that instance in the $helpers property so that it can be retrieved on any subsequent calls.

Parameters

string $name

Returns

\Dewdrop\View\Helper\AbstractHelper

castEscaperStringValue()

castEscaperStringValue(mixed  $input) : string

\Zend\Escaper\Escaper does not play well with falsey non-string values like null or false. It throws exceptions claiming it cannot convert them to utf-8. This method will convert false and null to an empty string and then cast the return value to a string (which should catch ints and floats as well).

Parameters

mixed $input

Returns

string