/** * Magic getter for {@link absoluteBaseUrl}; in the case that web request data * isn't available, it uses a config file. * * @return type */ public function getAbsoluteBaseUrl() { if (!isset($this->_absoluteBaseUrl)) { if (ResponseUtil::isCli()) { // It's assumed that in this case, we're dealing with (for example) // a cron script that sends emails and has to generate URLs. It // needs info about how to access the CRM from the outside... $this->_absoluteBaseUrl = ''; if ($this->contEd('pro') && $this->settings->externalBaseUrl && $this->settings->externalBaseUri) { // Use the base URL from "public info settings" since it's // available: $this->_absoluteBaseUrl = $this->settings->externalBaseUrl . $this->settings->externalBaseUri; } else { if ($file = realpath($this->owner->basePath . '/../webConfig.php')) { // Use the web API config file to construct the URL (our // last hope) include $file; if (isset($url)) { $this->_absoluteBaseUrl = $url; } } else { // There's nothing left we can legitimately do and have it // work correctly! Make something up. $this->_absoluteBaseUrl = 'http://localhost'; } } } else { $this->_absoluteBaseUrl = $this->owner->getBaseUrl(true); } } return $this->_absoluteBaseUrl; }
{ throw new Exception("I'm dyin'. Here's how."); } if (!isset($_GET['case'])) { die('Test case ("case") is a required parameter.'); } $c = $_GET['case']; $case = substr($c, 0, strpos($c, '.')); if ($case == '') { $case = $c; } $subcase = substr($c, strpos($c, '.') + 1); switch ($case) { case 'isCli': header('Content-type: text/plain'); echo (int) (!ResponseUtil::isCli()); break; case 'respond': ResponseUtil::$errorCode = 400; switch ($subcase) { case 'errTrue': ResponseUtil::respond($subcase, true); break; case 'errFalse': ResponseUtil::respond($subcase, false); break; case 'property': $r = new ResponseUtil(); $r['property'] = 'value'; ResponseUtil::respond($subcase, false); break;
/** * {@link isConsole} * @return bool */ public function getIsConsole() { if (!isset($this->_isConsole)) { $this->_isConsole = ResponseUtil::isCli(); } return $this->_isConsole; }
public function testIsCli() { $this->assertTrue(ResponseUtil::isCli()); $notCli = $this->getCurlResponse(array('{case}' => 'isCli')); $this->assertEquals(1, $notCli); }