使Zend \ Debug \ Debug :: dump()仅在开发模式下转储?

时间:2015-08-11 12:08:05

标签: zend-framework2

为了快速调试,我更喜欢SELECT c.PaperSalesCommissionWeekNumber FROM dbo.Deal AS d INNER JOIN dbo.Calender AS c ON d.DealDate = c.DateKey; 。问题:有时我忘记删除旧的转储语句,然后将它们投入生产。

如果Zend\Debug\Debug::dump()只打印了一些东西,当我在development mode时,会很棒。

有没有任何优雅的方法来实现这一点,而无需将Zend \ Debug \ Debug转换为服务?我喜欢简单的静态方法调用。可能通过在启用开发模式时设置env var?

1 个答案:

答案 0 :(得分:1)

/public/.htaccess添加此代码。 SetEnv APPLICATION_ENV "development"

/public/index.php文件中

/**
 * Set global ENV. Used for debugging
 */
if (isset($_SERVER['APPLICATION_ENV']) && $_SERVER["APPLICATION_ENV"] === 'development') {
    define("APP_ENV", 'development');
} else {
    define("APP_ENV", "production");
}

/**
 * Set default php.ini settings.
 *
 * Below lines includes security|error fixes
 */

/**
 * Handle reporting level
 */
error_reporting((APP_ENV === 'development' ? E_ALL : 0));

/**
 * Log errors into a file
 */
ini_set("log_errors", (APP_ENV === 'development'));

/**
 * Display of all other errors
 */
ini_set("display_errors", APP_ENV === 'development');

/**
 * Display of all startup errors
 */
ini_set("display_startup_errors", APP_ENV === 'development');

/**
 * Catch an error message emitted from PHP
 */
ini_set("track_errors", APP_ENV === 'development');

/**
 * Avoid serving non .php files as .php files
 */
ini_set('cgi.fix_pathinfo', 0);

/**
 * Helps mitigate xss
 */
ini_set('session.cookie_httponly', 1);

/**
 * Prevents session fixation
 */
ini_set('session.use_only_cookies', 1);

/**
 * Fixes files and server encoding
 */
mb_internal_encoding('UTF-8');

/**
 * Some server configurations are missing a date timezone
 */
if (ini_get('date.timezone') == '') {
    date_default_timezone_set('UTC');
}

当您的网站上线时,只需将.htaccess env变量更改为生产,所有调试选项都将消失。这就是我如何禁用这样的调试选项和模块,它工作正常。