/** * {@inheritdoc} */ public function startQuery($sql, array $params = null, array $types = null) { $this->query = null; if (!(\DBG::getMode() & DBG_DOCTRINE) && !(\DBG::getMode() & DBG_DOCTRINE_CHANGE) && !(\DBG::getMode() & DBG_DOCTRINE_ERROR)) { return; } // prepare SQL statement if ($params) { $sql = str_replace('?', "'%s'", $sql); //$this->query = vsprintf($sql, $params); foreach ($params as &$param) { // serialize arrays if (is_array($param)) { $param = serialize($param); } elseif (is_object($param)) { // serialize objects switch (get_class($param)) { case 'DateTime': // output DateTime object as date literal $param = $param->format(ASCMS_DATE_FORMAT_DATETIME); break; default: break; } } } $sql = vsprintf($sql, $params); } \DBG::logSQL($sql); $this->startTime = microtime(true); }
public function __construct() { if (\DBG::getMode() & DBG_ADODB_TRACE) { \DBG::enable_adodb_debug(true); } elseif (\DBG::getMode() & DBG_ADODB || \DBG::getMode() & DBG_ADODB_ERROR) { \DBG::enable_adodb_debug(); } else { \DBG::disable_adodb_debug(); } self::$em = \Env::get('em'); self::$defaultLang = \FWLanguage::getDefaultLangId(); $this->initModuleNames(); }
protected function execute() { switch ($this->mode) { case self::MODE_DQL: $this->result = ''; $strQuery = trim($this->code); $lister = new \Cx\Core_Modules\Listing\Controller\ListingController(function (&$offset, &$count, &$criteria, &$order) use($strQuery) { return \Env::get('em')->createQuery($strQuery); }); try { $table = new \BackendTable($lister->getData()); $this->result = $table->toHtml() . $lister; } catch (\Exception $e) { $this->result = 'Could not execute query (' . $e->getMessage() . ')!'; } break; case self::MODE_PHP: $dbgMode = \DBG::getMode(); try { // This error handler catches all Warnings and Notices and some Strict errors \DBG::activate(DBG_PHP); set_error_handler(array($this, 'phpErrorsAsExceptionsHandler')); $this->errrorHandlerActive = true; // Since DBG catches the rest (E_PARSE) let's use that ob_start(); $function = create_function('$em, $cx', '' . $this->code . ';'); $dbgContents = ob_get_clean(); \DBG::activate($dbgMode); if (!is_callable($function)) { // parse exception throw new SandboxException($dbgContents); } $this->result = var_export($function(\Env::get('em'), \Env::get('cx')), true); restore_error_handler(); $this->errrorHandlerActive = false; } catch (\Exception $e) { \DBG::activate($dbgMode); restore_error_handler(); $this->errrorHandlerActive = false; $this->result = get_class($e) . ': ' . $e->getMessage(); } break; default: break; } }
public static function getActivatedFlagsAsString() { $constants = get_defined_constants(true); $userConstants = array_keys($constants['user']); $flags = array_filter($userConstants, function ($constant) { return strpos($constant, 'DBG_') === 0 && constant($constant) && (\DBG::getMode() & constant($constant)) === constant($constant); }); return join(' | ', $flags); }
/** * Expands debugging behaviour with behaviour stored in session if specified and active. * * @access private */ private function restoreDebuggingParams() { if (isset($_SESSION['debugging']) && $_SESSION['debugging']) { DBG::activate(DBG::getMode() | $_SESSION['debugging_flags']); } }
/** * Expands debugging behaviour with behaviour stored in session if specified and active. * * @access protected */ protected function restoreDebuggingParams() { if (isset($this['debugging']) && $this['debugging']) { \DBG::activate(\DBG::getMode() | $this['debugging_flags']); } }