Fixes vim mode line.
[platal.git] / classes / pldict.php
CommitLineData
f4e68a78
FB
1<?php
2/***************************************************************************
e92ecb8c 3 * Copyright (C) 2003-2011 Polytechnique.org *
f4e68a78
FB
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22class PlDict
23{
24 private $array;
25
26 public function __construct(array $array = array())
27 {
28 $this->array = $array;
29 }
30
31 private function _get($key, $default)
32 {
33 return isset($this->array[$key]) ? $this->array[$key] : $default;
34 }
35
36 public function has($key)
37 {
38 return isset($this->array[$key]);
39 }
40
41 public function kill($key)
42 {
43 unset($this->array[$key]);
44 }
45
46 public function set($key, $value)
47 {
48 $this->array[$key] = $value;
49 }
50
51 public function v($key, $default = null)
52 {
53 return $this->_get($key, $default);
54 }
55
56 public function b($key, $default = false)
57 {
58 return (bool)$this->_get($key, $default);
59 }
60
61 public function s($key, $default = '')
62 {
63 return (string)$this->_get($key, $default);
64 }
65
66 public function t($key, $default = '')
67 {
68 return trim($this->s($key, $default));
69 }
70
71 public function blank($key, $strict = false)
72 {
73 if (!$this->has($key)) {
74 return true;
75 }
76 $var = $strict ? $this->s($key) : $this->t($key);
77 return empty($var);
78 }
79
80 public function i($key, $default = 0)
81 {
e24eb48b
FB
82 $i = to_integer($this->_get($key, $default));
83 return $i === false ? $default : $i;
f4e68a78
FB
84 }
85
86 public function l(array $keys)
87 {
88 return array_map(array($this, 'v'), $keys);
89 }
90
91 public function dict()
92 {
93 return $this->array;
94 }
42522e21
SJ
95
96 public function count()
97 {
98 return count($this->array);
99 }
100
101 public function merge(array $array)
102 {
103 $this->array = array_merge($this->array, $array);
104 }
f4e68a78
FB
105}
106
fa7ffd66 107// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
f4e68a78 108?>