PHP Class 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', '' );
Show file Open project: habari/system

Public Methods

Method Description
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

Private Methods

Method Description
__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.

Method Details

action_register_stackitems() public static method

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

add() public static method

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
return array The stack that was added to

create_stack() public static method

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
return array The created stack

dependent() public static method

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() public static method

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() public static method

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.
return mixed The item, or $default_value if it does not exist.

get_named_stack() public static method

Retreive a named stack instance
public static get_named_stack ( string $stack_name ) : Stack
$stack_name string The name of the stack to return
return Stack The requested stack

get_sorted_stack() public static method

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
return array A complete array of StackItems

has() public static method

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.
return boolean true if the item exists, false otherwise.

load_stackitems() public static method

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() public static method

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() public static method

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
return array The rest of the stack, post-remove

scripts() public static method

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