Skip to content

Commit

Permalink
check if class exists
Browse files Browse the repository at this point in the history
on first run, class may not exist and prevent dev/build from working (since preRequest is called before dev/build)

also change postRequest to check if clockwork exists instead of checking env (env might change between pre et post request)
  • Loading branch information
lekoala committed Sep 18, 2015
1 parent afbab84 commit 3b17c6b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ClockworkControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class ClockworkControllerExtension extends Extension
{
public function onBeforeInit() {
if (Director::isDev()) {
if (Director::isDev() && class_exists('Clockwork\\Request\\ClockworkTimeline')) {
Injector::inst()->get('ClockworkTimeline')->startEvent(
get_class($this->owner) . '_init',
get_class($this->owner) . ' initialization'
Expand All @@ -26,7 +26,7 @@ public function onBeforeInit() {
}

public function onAfterInit() {
if (Director::isDev()) {
if (Director::isDev() && class_exists('Clockwork\\Request\\ClockworkTimeline')) {
$injector = Injector::inst();
$injector->get('ClockworkTimeline')->endEvent(get_class($this->owner) . '_init');
$injector->get('ClockworkTimeline')->startEvent(
Expand Down
5 changes: 3 additions & 2 deletions src/RequestFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class RequestFilter implements \RequestFilter
* @return boolean Whether to continue processing other filters. Null or true will continue processing (optional)
*/
public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model) {
if (Director::isDev()) {
if (Director::isDev() && class_exists('Clockwork\\Clockwork')) {

$this->clockwork = new Clockwork();

// Wrap the current database adapter in a proxy object so we can log queries
Expand All @@ -59,7 +60,7 @@ public function preRequest(SS_HTTPRequest $request, Session $session, DataModel
* @return boolean Whether to continue processing other filters. Null or true will continue processing (optional)
*/
public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model) {
if (Director::isDev()) {
if (isset($this->clockwork)) {
$response->addHeader("X-Clockwork-Id", $this->clockwork->getRequest()->id);
$response->addHeader("X-Clockwork-Version", Clockwork::VERSION);
$response->addHeader('X-Clockwork-Path', Director::baseURL() . '__clockwork/');
Expand Down

0 comments on commit 3b17c6b

Please sign in to comment.