PHP Класс Habari\Stack

This class allows Habari to accumulate a group of unique values that can be output using a specific formatting string. This is useful for collecting a set of unique javascript references to output and then insert them at a specific point on the page. Add jquery to the javascript stack: Stack::add( 'template_header_javascript', Site::get_url('scripts') . '/jquery.js', 'jquery' ); Add stylesheet to theme_stylesheet stack with media type Stack::add( 'template_stylesheet', array( Site::get_url('theme') . '/style.css', 'screen' ), 'style' ); Output the javascript stack: Stack::out( 'template_header_javascript', '' ); Output the theme_stylesheet stack: Stack::out( 'template_stylesheet', '' );
Показать файл Открыть проект

Открытые методы

Метод Описание
action_register_stackitems ( ) Register CSS and script that can be added to the Stacks.
add ( string $stack_name, mixed $value, string $value_name = null, string $after = null ) : array Add a value to a stack
create_stack ( string $stack_name ) : array Creates and retreives a named stack instance
dependent ( string $dependent, string $dependson ) Make a stack's dependencies be provided by another stack
get ( string $stack_name, mixed $format = null ) Returns all of the values of the stack
get_item ( string $stack_name, $value_name, mixed $default_value = null ) : mixed Get a single item from a given stack.
get_named_stack ( string $stack_name ) : Stack Retreive a named stack instance
get_sorted_stack ( $stack_name ) : array Get the full list of StackItems in the correct order and with dependencies for a named stack
has ( string $stack_name, $value_name ) : boolean Check for the existence of a given stack item.
load_stackitems ( ) Allow plugins to register StackItems that can be added to Stacks later Initialize this class for plugin behavior so it can add system default StackItems
out ( string $stack_name, mixed $format = null ) Outputs all of the values of the stack
remove ( string $stack_name, string $value_name = null ) : array Remove a value to a stack
scripts ( string $element, mixed $attrib = null, string $wrapper = '%s' ) : string A callback for Stack::get() that outputs scripts as reference or inline depending on their content
styles ( string $element, string $typename = null, string $props = [] ) : string A callback for Stack::get() that outputs styles as link or inline style tags depending on their content

Приватные методы

Метод Описание
__construct ( mixed $input ) : array Private constructor for Stack.
is_url ( string $url ) : boolean Check if the passed string looks like a URL or an absolute path to a file.

Описание методов

action_register_stackitems() публичный статический Метод

Register CSS and script that can be added to the Stacks.
public static action_register_stackitems ( )

add() публичный статический Метод

Add a value to a stack
public static add ( string $stack_name, mixed $value, string $value_name = null, string $after = null ) : array
$stack_name string The name of the stack
$value mixed The value to add
$value_name string The name of the value to add
$after string The name of the stack element to insert this new element after
Результат array The stack that was added to

create_stack() публичный статический Метод

Creates and retreives a named stack instance
public static create_stack ( string $stack_name ) : array
$stack_name string The name of the stack to create and return
Результат array The created stack

dependent() публичный статический Метод

Make a stack's dependencies be provided by another stack
public static dependent ( string $dependent, string $dependson )
$dependent string The name of a stack that should be made to depend on another stack
$dependson string The name of the stack that the dependent stack should depend on

get() публичный статический Метод

Returns all of the values of the stack
public static get ( string $stack_name, mixed $format = null )
$stack_name string The name of the stack to output
$format mixed A printf-style formatting string or callback used to output each stack element

get_item() публичный статический Метод

Get a single item from a given stack.
public static get_item ( string $stack_name, $value_name, mixed $default_value = null ) : mixed
$stack_name string The name of the stack to fetch an item from.
$default_value mixed The default value to return if the item does not exist in the stack.
Результат mixed The item, or $default_value if it does not exist.

get_named_stack() публичный статический Метод

Retreive a named stack instance
public static get_named_stack ( string $stack_name ) : Stack
$stack_name string The name of the stack to return
Результат Stack The requested stack

get_sorted_stack() публичный статический Метод

Get the full list of StackItems in the correct order and with dependencies for a named stack
public static get_sorted_stack ( $stack_name ) : array
$stack_name
Результат array A complete array of StackItems

has() публичный статический Метод

Check for the existence of a given stack item.
public static has ( string $stack_name, $value_name ) : boolean
$stack_name string The name of the stack in which to check.
Результат boolean true if the item exists, false otherwise.

load_stackitems() публичный статический Метод

Allow plugins to register StackItems that can be added to Stacks later Initialize this class for plugin behavior so it can add system default StackItems
public static load_stackitems ( )

out() публичный статический Метод

Outputs all of the values of the stack
public static out ( string $stack_name, mixed $format = null )
$stack_name string The name of the stack to output
$format mixed A printf-style formatting string or callback used to output each stack element

remove() публичный статический Метод

Remove a value to a stack
public static remove ( string $stack_name, string $value_name = null ) : array
$stack_name string The name of the stack
$value_name string The name of the value to remove
Результат array The rest of the stack, post-remove

scripts() публичный статический Метод

A callback for Stack::get() that outputs scripts as reference or inline depending on their content
public static scripts ( string $element, mixed $attrib = null, string $wrapper = '%s' ) : string
$element string The script element in the stack
$attrib mixed Additional attributes, like 'defer' or 'async' allowed for