예제 #1
0
 /**
  * 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;
 }
예제 #2
0
{
    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;
예제 #3
0
 /**
  * {@link isConsole}
  * @return bool
  */
 public function getIsConsole()
 {
     if (!isset($this->_isConsole)) {
         $this->_isConsole = ResponseUtil::isCli();
     }
     return $this->_isConsole;
 }
예제 #4
0
 public function testIsCli()
 {
     $this->assertTrue(ResponseUtil::isCli());
     $notCli = $this->getCurlResponse(array('{case}' => 'isCli'));
     $this->assertEquals(1, $notCli);
 }