Habari\Stack::add PHP Method

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
    public static function add($stack_name, $value, $value_name = null, $after = null)
    {
        $stack = self::get_named_stack($stack_name);
        if ($value_name == null && is_string($value)) {
            if ($test = StackItem::get($value)) {
                $value = $test;
            }
        }
        if (!$value instanceof StackItem) {
            $value_name = $value_name ? $value_name : md5(serialize($value));
            $value = StackItem::register($value_name, $value);
            foreach ((array) $after as $a) {
                $value->add_dependency($a);
            }
        }
        $stack[$value->name] = $value;
        self::$stacks[$stack_name] = $stack;
        return $stack;
    }