Exemple #1
0
 public function setDefaultFlags()
 {
     $isCli = !System::isFunctionDisabled('php_sapi_name') && php_sapi_name() === 'cli';
     $this->setFlag(self::FLAG_CLI, $isCli);
     $this->setFlag(self::FLAG_WEB, !$isCli);
     return $this;
 }
Exemple #2
0
 public function testMsleep()
 {
     //Test no output
     $this->expectOutputString('');
     $time = microtime(true);
     System::msleep(1);
     $deltaMs = (microtime(true) - $time) * 1000;
     //Microtime appears to be a fairly unreliable way to check
     //Below assertion disabled due to flakey validation
     //$this->assertTrue($deltaMs > 0.1 && $deltaMs < 1.5);
 }
Exemple #3
0
 protected function runCommand($command)
 {
     $exitCode = 0;
     $method = $this->_executeMethod;
     if (System::commandExists('bash')) {
         // Use bash to execute if available,
         // enables CTRL+C to also kill spawned process (cygwin issue)
         $command = "bash -c '{$command}'";
     }
     $method($command, $exitCode);
     return $exitCode;
 }
 /**
  * Sleep for X milliseconds
  *
  * @param $milliseconds
  *
  * @deprecated
  */
 function msleep($milliseconds)
 {
     \Packaged\Helpers\System::msleep($milliseconds);
 }
Exemple #5
0
 public function visitorProvider()
 {
     $whois = System::commandExists('whois');
     return [['127.0.0.1', 'GB', 'London', 'eng'], ['127.0.0.1', 'UK', 'Portsmouth', 'england', new ConfigSection('http_visitor', ['city' => 'Portsmouth', 'country' => 'UK', 'region' => 'england'])], ['208.67.222.222', $whois ? 'US' : 'GB', $whois ? 'San Francisco' : 'London', $whois ? 'CA' : 'eng', new ConfigSection('http_visitor', ['whois' => true])]];
 }
Exemple #6
0
 /**
  * (PHP 5 &gt;= 5.4.0)<br/>
  * Specify data which should be serialized to JSON
  * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
  * @return mixed data which can be serialized by <b>json_encode</b>,
  * which is a value of any type other than a resource.
  */
 public function jsonSerialize()
 {
     // HHVM does not json_encode
     if (System::isHHVM()) {
         $values = get_public_properties($this);
         foreach ($values as $k => $v) {
             if ($v instanceof \DateTime) {
                 $values[$k] = ['date' => $v->format('Y-m-d H:i:s'), 'timezone_type' => 1, 'timezone' => $v->format('O')];
             }
         }
         return $values;
     }
     return $this;
 }
Exemple #7
0
 protected function _fromWhois()
 {
     if (System::commandExists('whois')) {
         exec("whois " . $this->_ip, $whois);
         $whois = implode("\n", $whois);
         $countries = $cities = $regions = [];
         preg_match_all('/^country:\\s*([A-Z]{2})/mi', $whois, $countries);
         if (isset($countries[1]) && !empty($countries[1])) {
             $this->_country = end($countries[1]);
         }
         preg_match_all('/^city:\\s*([A-Z].*$)/mi', $whois, $cities);
         if (isset($cities[1]) && !empty($cities[1])) {
             $this->_city = end($cities[1]);
         }
         preg_match_all('/^(state|stateprov|county|prov|province):\\s*([A-Z].*$)/mi', $whois, $regions);
         if (isset($regions[2]) && !empty($regions[1])) {
             $this->_region = end($regions[2]);
         }
     }
 }