sharing namespace_dir and the namespace string methods

This commit is contained in:
lakedaemon
2016-05-28 08:15:43 +02:00
parent cd1493b082
commit 61b101d442
5 changed files with 67 additions and 102 deletions

View File

@@ -984,26 +984,12 @@ namespace php {
bool needs_imports) {
if (!classcode.length()) return true;
std::string namespace_name;
std::string namespace_dir = path_;
auto &namespaces = parser_.namespaces_.back()->components;
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
if (namespace_name.length()) {
namespace_name += "\\";
namespace_dir += kPathSeparator;
}
namespace_name += *it;
namespace_dir += *it;
EnsureDirExists(namespace_dir.c_str());
}
std::string code = "";
BeginFile(namespace_name, needs_imports, &code);
BeginFile(FullNamespace("\\"), needs_imports, &code);
code += classcode;
std::string filename =
namespace_dir + kPathSeparator + def.name + ".php";
namespace_dir_ + kPathSeparator + def.name + ".php";
return SaveFile(filename.c_str(), code, false);
}
};