Release
[hcoop/zz_old/debian/suphp.git] / src / Environment.cpp
CommitLineData
623e7ab4 1/*
2 suPHP - (c)2002-2005 Sebastian Marsching <sebastian@marsching.com>
3
4 This file is part of suPHP.
5
6 suPHP 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 suPHP 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 suPHP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21#include <stdexcept>
22#include <string>
23
24#include "KeyNotFoundException.hpp"
25
26#include "Environment.hpp"
27
28using namespace suPHP;
29
30std::string suPHP::Environment::getVar(const std::string& name) const
31 throw (KeyNotFoundException) {
32 if (this->vars.find(name) != this->vars.end()) {
33 return this->vars.find(name)->second;
34 } else {
35 throw KeyNotFoundException("Key " + name + " not found",
36 __FILE__, __LINE__);
37 }
38}
39
40void suPHP::Environment::setVar(const std::string name,
41 const std::string content)
42 throw (KeyNotFoundException) {
43 if (this->vars.find(name) != this->vars.end()) {
44 this->vars.find(name)->second = content;
45 } else {
46 throw KeyNotFoundException("Key " + name + " not found",
47 __FILE__, __LINE__);
48 }
49}
50
51void suPHP::Environment::putVar(const std::string name,
52 const std::string content) {
53 if (this->vars.find(name) != this->vars.end()) {
54 this->vars.find(name)->second = content;
55 } else {
56 std::pair<std::string, std::string> p;
57 p.first = name;
58 p.second = content;
59 this->vars.insert(p);
60 }
61
62}
63
64void suPHP::Environment::deleteVar(const std::string& name)
65 throw (KeyNotFoundException) {
66 if (this->vars.find(name) != this->vars.end()) {
67 this->vars.erase(name);
68 } else {
69 throw KeyNotFoundException("Key " + name + " not found",
70 __FILE__, __LINE__);
71 }
72}
73
74bool suPHP::Environment::hasVar(const std::string& name) const {
75 if (this->vars.find(name) != this->vars.end()) {
76 return true;
77 } else {
78 return false;
79 }
80
81}
82
83std::string& suPHP::Environment::operator[](const std::string& name)
84 throw (KeyNotFoundException) {
85 if (this->vars.find(name) != this->vars.end()) {
86 return this->vars.find(name)->second;
87 } else {
88 throw KeyNotFoundException("Key " + name + " not found",
89 __FILE__, __LINE__);
90 }
91}
92
93
94const std::map<std::string, std::string>& suPHP::Environment::getBackendMap()
95 const {
96 return this->vars;
97}