de-dup THREAD_LOCAL macros
[hiphop-php.git] / hphp / runtime / server / source-root-info.h
blobe670518d684ed46937494fc64c285d9e95f61f0d
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_SOURCE_ROOT_INFO_H_
18 #define incl_HPHP_SOURCE_ROOT_INFO_H_
20 #include "hphp/runtime/base/type-array.h"
21 #include "hphp/runtime/base/type-string.h"
22 #include "hphp/runtime/debugger/debugger_base.h"
24 namespace HPHP {
25 ///////////////////////////////////////////////////////////////////////////////
27 struct Transport;
29 struct SourceRootInfo {
30 explicit SourceRootInfo(Transport* transport);
31 SourceRootInfo(const std::string &user, const std::string &sandbox);
32 void createFromUserConfig();
33 void createFromCommonRoot(const String &sandboxName);
35 ~SourceRootInfo();
37 // Set SERVER variables in array, and return the modified version.
38 // You'll likely want to ensure the array coming in is a temporary
39 // (so it can be modified in place).
40 Array setServerVariables(Array server) const;
42 std::string path() const;
44 bool sandboxOn() const {
45 return m_sandboxCond == SandboxCondition::On;
48 void clear() {
49 m_user.reset();
50 m_sandbox.reset();
51 m_path.reset();
52 m_serverVars.reset();
55 bool error() const {
56 return m_sandboxCond == SandboxCondition::Error;
58 void handleError(Transport *t);
59 static const std::string &GetCurrentSourceRoot() {
60 return s_path.isNull() ? RuntimeOption::SourceRoot : *s_path;
63 static String RelativeToPhpRoot(const String& path) {
64 String ret = GetCurrentSourceRoot();
65 ret += path;
66 return ret;
69 Eval::DSandboxInfo getSandboxInfo() const;
71 private:
72 static const std::string& GetCurrentPhpRoot() {
73 return s_phproot.isNull() ? initPhpRoot() : *s_phproot;
76 private:
77 String m_user;
78 String m_sandbox;
79 String m_path;
80 enum class SandboxCondition {
81 On,
82 Error,
83 Off
84 } m_sandboxCond;
85 Array m_serverVars;
86 static THREAD_LOCAL_NO_CHECK(std::string, s_path);
87 static THREAD_LOCAL_NO_CHECK(std::string, s_phproot);
89 static std::string& initPhpRoot();
90 std::string parseSandboxServerVariable(const std::string &format) const;
93 ///////////////////////////////////////////////////////////////////////////////
96 #endif // incl_HPHP_SOURCE_ROOT_INFO_H_