wxString PHPCodeCompletion::ExpandRequire(const wxFileName& curfile, const wxString& require) { PHPScanner_t scanner = ::phpLexerNew("<?php " + require); if(!scanner) return ""; wxString outFile; phpLexerToken token; while(::phpLexerNext(scanner, token)) { if(token.IsAnyComment()) continue; switch(token.type) { case kPHP_T_REQUIRE: case kPHP_T_REQUIRE_ONCE: break; case kPHP_T_CONSTANT_ENCAPSED_STRING: { wxString str = token.text; str.Trim().Trim(false); // strip the " or ' from the string str.Remove(0, 1).RemoveLast(); outFile << str; break; } case kPHP_T_FILE: outFile << curfile.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); break; case kPHP_T_DIR: outFile << curfile.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); break; } } wxFileName fileName(outFile); if(fileName.IsOk() && fileName.IsRelative()) { wxArrayString paths; paths.Add(curfile.GetPath()); // Relative path, we try to resolve it by looking at the include path give to us PHPProject::Ptr_t proj = PHPWorkspace::Get()->GetActiveProject(); if(proj) { wxArrayString incpaths = proj->GetSettings().GetIncludePathAsArray(); paths.insert(paths.end(), incpaths.begin(), incpaths.end()); } for(size_t i = 0; i < paths.GetCount(); ++i) { wxFileName tmpFile = fileName; if(tmpFile.MakeAbsolute(paths.Item(i))) { wxString fullpath = tmpFile.GetFullPath(); if(wxFileName::Exists(fullpath)) { fileName = tmpFile; break; } } } } if(fileName.IsOk()) { fileName.Normalize(); outFile = fileName.GetFullPath(); } ::phpLexerDestroy(&scanner); return outFile; }
void XDebugManager::DoApplyBreakpoints() { CL_DEBUG("CodeLite >>> Applying breakpoints"); CHECK_PTR_RET(m_readerThread); PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetActiveProject(); CHECK_PTR_RET(pProject); const PHPProjectSettingsData& settings = pProject->GetSettings(); bool bRunAsWebserver = ( pProject->GetSettings().GetRunAs() == PHPProjectSettingsData::kRunAsWebsite); XDebugBreakpoint::List_t& breakpoints = m_breakpointsMgr.GetBreakpoints(); XDebugBreakpoint::List_t::iterator iter = breakpoints.begin(); for( ; iter != breakpoints.end(); ++iter ) { // apply only breakpoints without xdebug-id attached to them if ( iter->IsApplied() ) { continue; } wxStringMap_t sftpMapping; SSHWorkspaceSettings sftpSettings; sftpSettings.Load(); if ( !sftpSettings.GetRemoteFolder().IsEmpty() && sftpSettings.IsRemoteUploadEnabled() ) { sftpMapping.insert( std::make_pair(PHPWorkspace::Get()->GetFilename().GetPath(), sftpSettings.GetRemoteFolder()) ); } wxString command; XDebugCommandHandler::Ptr_t handler( new XDebugBreakpointCmdHandler(this, ++TranscationId, *iter) ); wxString filepath = bRunAsWebserver ? settings.GetMappdPath( iter->GetFileName(), true , sftpMapping) : iter->GetFileName(); command << "breakpoint_set -i " << handler->GetTransactionId() << " -t line" << " -f " << filepath << " -n " << iter->GetLine(); DoSocketWrite( command ); AddHandler( handler ); } }
wxString MapRemoteFileToLocalFile(const wxString& remoteFile) { // Check that a workspace is opened if(!PHPWorkspace::Get()->IsOpen()) return remoteFile; // Sanity PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetActiveProject(); if(!pProject) return remoteFile; // Map filename file attribute returned by xdebug to local filename wxString filename = remoteFile; // Remote the "file://" from the file path filename.StartsWith(FILE_SCHEME, &filename); CL_DEBUG("filename => %s", filename); // On Windows, the file is returned like (after removing the file://) // /C:/Http/htdocs/file.php - remote the leading "/" wxRegEx reMSWPrefix("/[a-zA-Z]{1}:/"); if(reMSWPrefix.IsValid() && reMSWPrefix.Matches(filename)) { // Windows file CL_DEBUG("filename => %s", filename); filename.Remove(0, 1); } // Remove URI encoding ("%20"=>" " etc) DecodeFileName(filename); CL_DEBUG("filename => %s", filename); // First check if the remote file exists locally if(wxFileName(filename).Exists()) { return wxFileName(filename).GetFullPath(); } // Use the active project file mapping const PHPProjectSettingsData& settings = pProject->GetSettings(); const JSONElement::wxStringMap_t& mapping = settings.GetFileMapping(); JSONElement::wxStringMap_t::const_iterator iter = mapping.begin(); for(; iter != mapping.end(); ++iter) { const wxString& localFolder = iter->first; const wxString& remoteFolder = iter->second; if(filename.StartsWith(remoteFolder)) { filename.Replace(remoteFolder, localFolder); return wxFileName(filename).GetFullPath(); } } // No matching was found return remoteFile; }
wxStringMap_t XDebugManager::GetFileMapping(PHPProject::Ptr_t pProject) const { wxASSERT(pProject); wxStringMap_t mappings; const PHPProjectSettingsData& settings = pProject->GetSettings(); mappings = settings.GetFileMapping(); // Add the SFTP mappings SSHWorkspaceSettings sftpSettings; sftpSettings.Load(); if ( !sftpSettings.GetRemoteFolder().IsEmpty() && sftpSettings.IsRemoteUploadEnabled() ) { mappings.insert( std::make_pair(PHPWorkspace::Get()->GetFilename().GetPath(), sftpSettings.GetRemoteFolder()) ); } return mappings; }
void PHPProjectSettingsDlg::Save() { PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(m_projectName); CHECK_PTR_RET(pProject); PHPProjectSettingsData& data = pProject->GetSettings(); // General settings data.SetRunAs(m_choicebook1->GetSelection() == 0 ? PHPProjectSettingsData::kRunAsCLI : PHPProjectSettingsData::kRunAsWebsite); data.SetPhpExe(m_filePickerPHPExe->GetPath()); data.SetIndexFile(m_filePickerIndex->GetPath()); data.SetArgs(m_textCtrlProgramArgs->GetValue()); data.SetWorkingDirectory(m_dirPickerWorkingDirectory->GetPath()); data.SetIncludePath(m_textCtrlPHPIncludePath->GetValue()); data.SetPauseWhenExeTerminates(m_checkBoxPauseWhenExecutionEnds->IsChecked()); data.SetPhpIniFile(m_filePickerPhpIni->GetPath()); data.SetProjectURL(m_textCtrlWebSiteURL->GetValue()); data.SetUseSystemBrowser(m_checkBoxSystemBrowser->IsChecked()); // Code Completion settings data.SetCcIncludePath(m_textCtrlCCIncludePath->GetValue()); // Save the file mapping JSONElement::wxStringMap_t mapping; int itemCount = m_dvListCtrlFileMapping->GetItemCount(); for(int i = 0; i < itemCount; ++i) { wxVariant source, target; m_dvListCtrlFileMapping->GetValue(source, i, 0); m_dvListCtrlFileMapping->GetValue(target, i, 1); mapping.insert(std::make_pair(source.GetString(), target.GetString())); } data.SetFileMapping(mapping); wxString fileExts = m_pgPropFileTypes->GetValue().GetString(); fileExts.Replace(",", ";"); pProject->SetImportFileSpec(fileExts); wxString excludeDirs = m_pgPropExcludeFolders->GetValue().GetString(); excludeDirs.Replace(",", ";"); pProject->SetExcludeFolders(excludeDirs); // Save the project content pProject->Save(); SetDirty(false); }
void PHPWorkspaceView::OnMakeIndexPHP(wxCommandEvent& e) { e.Skip(); wxTreeItemId item = DoGetSingleSelection(); CHECK_ITEM_RET(item); ItemData* itemData = DoGetItemData(item); CHECK_PTR_RET(itemData); CHECK_ID_FILE(itemData); wxString projectName = itemData->GetProjectName(); if(projectName.IsEmpty()) return; PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(projectName); CHECK_PTR_RET(pProject); PHPProjectSettingsData& settings = pProject->GetSettings(); settings.SetIndexFile(itemData->GetFile()); pProject->Save(); }
void PHPWorkspace::ParseWorkspace(bool full) { // Request for parsing if(full) { // a full parsing is needed, stop the paser thread // close the database, delete it and recreate it // then, restart the parser thread PHPParserThread::Clear(); PHPParserThread::Release(); // Stop and wait the thread terminates // Close the CC manager PHPCodeCompletion::Instance()->Close(); // Delete the file wxFileName fnDatabaseFile(m_workspaceFile.GetPath(), "phpsymbols.db"); fnDatabaseFile.AppendDir(".codelite"); wxLogNull noLog; bool bRemoved = ::wxRemoveFile(fnDatabaseFile.GetFullPath()); wxUnusedVar(bRemoved); // Start the managers again PHPParserThread::Instance()->Start(); PHPCodeCompletion::Instance()->Open(m_workspaceFile); } PHPParserThreadRequest* req = new PHPParserThreadRequest(PHPParserThreadRequest::kParseWorkspaceFilesQuick); req->workspaceFile = GetFilename().GetFullPath(); GetWorkspaceFiles(req->files); // Append the current project CC include paths PHPProject::Ptr_t pProject = GetActiveProject(); if(pProject) { PHPProjectSettingsData& settings = pProject->GetSettings(); req->frameworksPaths = settings.GetCCIncludePathAsArray(); } PHPParserThread::Instance()->Add(req); }