Arquivos
hhvm/hphp/runtime/ext/extension.cpp
T
Sara Golemon 1824c359ea Pass entire Hdf to Extension::moduleLoad()
This lets us move parsing of runtime options
to the extensions which actually use them.

Nobody is currently using this functionality, so changing
what gets passed isn't a BC break worth worrying about.

I'll post some followup diffs pulling things out of
RuntimeOptions.
2013-07-24 10:35:46 -07:00

111 linhas
3.8 KiB
C++

/*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
| Copyright (c) 1997-2010 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#include "hphp/runtime/ext/extension.h"
#include "hphp/runtime/base/complex_types.h"
#include "hphp/runtime/base/runtime_option.h"
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////
typedef std::map<std::string, Extension*, stdltistr> ExtensionMap;
static ExtensionMap *s_registered_extensions = NULL;
static bool s_modules_initialised = false;
// just to make valgrind cleaner
class ExtensionUninitializer {
public:
~ExtensionUninitializer() {
delete s_registered_extensions;
}
};
static ExtensionUninitializer s_extension_uninitializer;
///////////////////////////////////////////////////////////////////////////////
Extension::Extension(litstr name, const char *version /* = "" */)
: m_name(StringData::GetStaticString(name))
, m_version(version ? version : "") {
if (s_registered_extensions == NULL) {
s_registered_extensions = new ExtensionMap();
}
assert(s_registered_extensions->find(name) ==
s_registered_extensions->end());
(*s_registered_extensions)[name] = this;
}
void Extension::LoadModules(Hdf hdf) {
assert(s_registered_extensions);
for (ExtensionMap::const_iterator iter = s_registered_extensions->begin();
iter != s_registered_extensions->end(); ++iter) {
iter->second->moduleLoad(hdf);
}
}
void Extension::InitModules() {
assert(s_registered_extensions);
for (ExtensionMap::const_iterator iter = s_registered_extensions->begin();
iter != s_registered_extensions->end(); ++iter) {
iter->second->moduleInit();
}
s_modules_initialised = true;
}
bool Extension::ModulesInitialised() {
return s_modules_initialised;
}
void Extension::ShutdownModules() {
assert(s_registered_extensions);
for (ExtensionMap::const_iterator iter = s_registered_extensions->begin();
iter != s_registered_extensions->end(); ++iter) {
iter->second->moduleShutdown();
}
s_registered_extensions->clear();
}
bool Extension::IsLoaded(CStrRef name) {
if (name == "apc") {
return RuntimeOption::EnableApc;
}
assert(s_registered_extensions);
return s_registered_extensions->find(name.data()) !=
s_registered_extensions->end();
}
Extension *Extension::GetExtension(CStrRef name) {
assert(s_registered_extensions);
ExtensionMap::iterator iter = s_registered_extensions->find(name.data());
if (iter != s_registered_extensions->end()) {
return iter->second;
}
return NULL;
}
Array Extension::GetLoadedExtensions() {
assert(s_registered_extensions);
Array ret = Array::Create();
for (ExtensionMap::const_iterator iter = s_registered_extensions->begin();
iter != s_registered_extensions->end(); ++iter) {
ret.append(iter->second->m_name);
}
return ret;
}
///////////////////////////////////////////////////////////////////////////////
}