123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace Elgg;
- final class Context {
-
- private $stack = array();
-
-
- public function peek() {
- $last = end($this->stack);
- return ($last === false) ? null : $last;
- }
-
-
- public function push($context) {
- $this->stack[] = "$context";
- }
-
-
- public function pop() {
- return array_pop($this->stack);
- }
-
-
- public function set($context) {
- $context = trim($context);
- if (empty($context)) {
- return false;
- }
- $context = strtolower($context);
- $this->pop();
- $this->push($context);
- return true;
- }
-
- public function contains($context) {
- return in_array($context, $this->stack);
- }
-
- public function toArray() {
- return $this->stack;
- }
-
- public function fromArray(array $stack) {
- $this->stack = array_map('strval', $stack);
- }
- }
|