Elgg  Version 1.11
Context.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg;
3 
27 final class Context {
28 
29  private $stack = array();
30 
36  public function peek() {
37  $last = end($this->stack);
38  return ($last === false) ? null : $last;
39  }
40 
47  public function push($context) {
48  $this->stack[] = "$context";
49  }
50 
56  public function pop() {
57  return array_pop($this->stack);
58  }
59 
66  public function set($context) {
67  $context = trim($context);
68 
69  if (empty($context)) {
70  return false;
71  }
72 
73  $context = strtolower($context);
74 
75  $this->pop();
76  $this->push($context);
77 
78  return true;
79  }
80 
92  public function contains($context) {
93  return in_array($context, $this->stack);
94  }
95 
101  public function toArray() {
102  return $this->stack;
103  }
104 
111  public function fromArray(array $stack) {
112  $this->stack = array_map('strval', $stack);
113  }
114 }
peek()
Get the most recently pushed context value.
Definition: Context.php:36
$context
Definition: add.php:11
pop()
Removes and returns the top context string from the stack.
Definition: Context.php:56
contains($context)
Check if this context exists anywhere in the stack.
Definition: Context.php:92
push($context)
Push a context onto the top of the stack.
Definition: Context.php:47
toArray()
Get the entire context stack as an array (e.g.
Definition: Context.php:101
Save menu items.
fromArray(array $stack)
Overwrite the entire context stack from an array of strings.
Definition: Context.php:111