Elgg  Version 2.3
Context.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg;
3 
24 final class Context {
25 
26  private $stack = array();
27 
33  public function peek() {
34  $last = end($this->stack);
35  return ($last === false) ? null : $last;
36  }
37 
44  public function push($context) {
45  $this->stack[] = "$context";
46  }
47 
53  public function pop() {
54  return array_pop($this->stack);
55  }
56 
63  public function set($context) {
64  $context = trim($context);
65 
66  if (empty($context)) {
67  return false;
68  }
69 
70  $context = strtolower($context);
71 
72  $this->pop();
73  $this->push($context);
74 
75  return true;
76  }
77 
89  public function contains($context) {
90  return in_array($context, $this->stack);
91  }
92 
98  public function toArray() {
99  return $this->stack;
100  }
101 
108  public function fromArray(array $stack) {
109  $this->stack = array_map('strval', $stack);
110  }
111 }
peek()
Get the most recently pushed context value.
Definition: Context.php:33
$context
Definition: add.php:11
pop()
Removes and returns the top context string from the stack.
Definition: Context.php:53
contains($context)
Check if this context exists anywhere in the stack.
Definition: Context.php:89
push($context)
Push a context onto the top of the stack.
Definition: Context.php:44
toArray()
Get the entire context stack as an array (e.g.
Definition: Context.php:98
Save menu items.
fromArray(array $stack)
Overwrite the entire context stack from an array of strings.
Definition: Context.php:108
Manages a global stack of strings for sharing information about the current execution context...
Definition: Context.php:24