public function configure(array $data) { $userId = dmArray::get($data, 'user_id', $this->serviceContainer->getService('user')->getUserId()); if (!$userId && dmConfig::isCli()) { $userId = 'task'; } $this->data = array('time' => (string) $data['server']['REQUEST_TIME'], 'ip' => (string) $this->getCurrentRequestIp(), 'session_id' => (string) session_id(), 'user_id' => (string) $userId, 'action' => (string) $data['action'], 'type' => (string) $data['type'], 'subject' => dmString::truncate($data['subject'], 500), 'record' => isset($data['record']) ? get_class($data['record']) . ':' . $data['record']->get('id') : ''); }
protected function redirectNoScriptName() { if (!sfConfig::get('sf_no_script_name') || dmConfig::isCli()) { return; } $absoluteUrlRoot = $this->request->getAbsoluteUrlRoot(); if (0 === strpos($this->request->getUri(), $absoluteUrlRoot . '/index.php')) { $this->context->getController()->redirect(str_replace($absoluteUrlRoot . '/index.php', $absoluteUrlRoot, $this->request->getUri()), 0, 301); } }
protected function connectServices() { if (!dmConfig::isCli()) { /* * Connect the tree watcher to make it aware of database modifications */ $this->getService('page_tree_watcher')->connect(); /* * Connect the cache cleaner */ $this->getService('cache_cleaner')->connect(); } if ('test' != sfConfig::get('sf_environment')) { /* * Connect the error watcher to make it aware of thrown exceptions */ $this->getService('error_watcher')->connect(); /* * Connect the event log to make it aware of database modifications */ $this->getService('event_log')->connect(); /* * Connect the request log to make it aware of controller end */ $this->getService('request_log')->connect(); } if ($this->getService('response')->isHtmlForHuman()) { /* * Enable stylesheet compression */ $this->getService('stylesheet_compressor')->connect(); /* * Enable javascript compression */ $this->getService('javascript_compressor')->connect(); } $this->getService('user')->connect(); /* * Enable page i18n builder for multilingual sites */ $cultures = $this->getService('i18n')->getCultures(); if (count($cultures) > 1) { $this->mergeParameter('page_i18n_builder.options', array('cultures' => $cultures)); $this->getService('page_i18n_builder')->connect(); } /* * Disable logging when request has a dm_nolog parameter */ if ($this->getService('request')->getParameter('dm_nolog')) { $this->getService('event_log')->setOption('enabled', false); $this->getService('request_log')->setOption('enabled', false); } }
protected function redirectTrailingSlash() { if (dmConfig::isCli()) { return; } $uri = $this->request->getUri(); if ('/' === substr($uri, -1)) { if ($uri !== $this->request->getAbsoluteUrlRoot() . '/') { $this->context->getController()->redirect(rtrim($uri, '/'), 0, 301); } } }
protected function checkProjectIsSetup() { if (file_exists(sfConfig::get('dm_data_dir') . '/lock')) { if (!dmConfig::isCli()) { die('Please setup this project with the dm:setup task : "php symfony dm:setup"'); } return false; } return true; }
protected static function debugger($var, $level = 1, $opt = array()) { $CR = "\n"; $die = $level > 2; $opt = dmString::toArray($opt); if (!sfConfig::get('sf_debug') && !dmArray::get($opt, "force")) { return; } $tag = dmArray::get($opt, "tag", "pre"); if (dmArray::get($opt, "to_string", false) && is_array($var)) { array_walk_recursive($var, create_function('&$val', 'if(is_object($val)) { if (method_exists($val, "toString")) { $val = get_class($val)." : ".$val->toString(); } elseif (method_exists($val, "__toString")) { $val = get_class($val)." : ".$val->__toString(); } }')); } elseif (is_array($var)) { array_walk_recursive($var, create_function('&$val', 'if(is_object($val)) { if (method_exists($val, "toDebug")) { $val = get_class($val)." : ".print_r($val->toDebug(), true); } elseif (method_exists($val, "toArray")) { $val = get_class($val)." : ".print_r($val->toArray(), true); } }')); } if (dmConfig::isCli()) { $debugString = print_r($var, true); $debugString = substr($debugString, 0, self::MAX_DEBUG_LENGTH); echo $debugString; if (strlen($debugString) > self::MAX_DEBUG_LENGTH) { echo "\n---TRUNCATED---\n"; } if ($die) { die; } } else { array_walk_recursive($var, create_function('&$val', 'if(is_string($val)) { $val = htmlspecialchars($val); }')); if (count($var) == 1) { $var = dmArray::first($var); } if (dmContext::hasInstance() && ($request = dm::getRequest())) { if ($request->isXmlHttpRequest()) { echo "\n<{$tag}>"; $debugString = print_r($var, true); echo substr($debugString, 0, self::MAX_DEBUG_LENGTH); if (strlen($debugString) > self::MAX_DEBUG_LENGTH) { echo "\n---TRUNCATED---\n"; } echo "</{$tag}>\n"; if ($die) { die; } return; } } ob_start(); if ($level > 1) { print '<br /><' . $tag . ' style="text-align: left; border: 1px solid #aaa; border-left-width: 10px; background-color: #f4F4F4; color: #000; margin: 3px; padding: 3px; font-size: 11px;">'; $debugString = print_r($var, true); echo substr($debugString, 0, self::MAX_DEBUG_LENGTH); if (strlen($debugString) > self::MAX_DEBUG_LENGTH) { echo "\n---TRUNCATED---\n"; } print "</{$tag}>"; } $buffer = ob_get_clean(); if ($level == 4) { ob_start(); echo '<pre>'; debug_print_backtrace(); echo '</pre>'; $dieMsg = ob_get_clean(); } else { $backtrace = debug_backtrace(); $dieMsg = str_replace(sfConfig::get("sf_root_dir"), "", dmArray::get($backtrace[1], 'file')) . " l." . dmArray::get($backtrace[1], 'line'); // $dieMsg = '<pre>'; // $dieMsg .= isset($backtrace[0]['file']) ? '> file : <b>'. // $backtrace[1]['file'] .'</b>'. $CR : ''; // $dieMsg .= isset($backtrace[0]['line']) ? '> line : <b>'. // $backtrace[1]['line'] .'</b>'. $CR : ''; // $dieMsg .= isset($backtrace[1]['class']) ? '> class : <b>'. // dmArray::get(dmArray::get($backtrace, 2, array()), 'class') .'</b>'. $CR : ''; // $dieMsg .= isset($backtrace[1]['function']) ? '> function : <b>'. // dmArray::get(dmArray::get($backtrace, 2, array()), 'function') .'</b>'. $CR : ''; // $dieMsg .= '</pre>'; } if ($level > 1) { print $buffer; if ($die) { die($dieMsg); } else { print $dieMsg; } } else { sfWebDebug::getInstance()->logShortMessage($buffer . $dieMsg); } } }