Ejemplo n.º 1
0
 /**
  * @param array $columns
  * @return $this
  * @see schemaColumnSet
  */
 protected function schemaColumnsSet($columns)
 {
     foreach ($columns as $name => $data) {
         $default = array_get_unset($data, 'default');
         $this->schemaColumnSet($name, $data, $default);
     }
     return $this;
 }
Ejemplo n.º 2
0
Archivo: net.php Proyecto: tapiau/muyo
 /**
  * @param array $packet
  * @param array $response
  * @return string
  */
 function rest_send($packet, &$response = [])
 {
     debug_enforce(is_array($packet));
     if (array_key_exists('Url', $packet)) {
         $url = @parse_url(array_get_unset($packet, 'Url'));
         debug_enforce(false !== $url, 'Invalid URL');
         if (array_key_exists('scheme', $url)) {
             $packet['Scheme'] = $url['scheme'];
         }
         $packet['Host'] = array_key_exists('host', $url) ? $url['host'] : 'localhost';
         if (array_key_exists('port', $url)) {
             $packet['Port'] = $url['port'];
         }
         $packet['Path'] = array_key_exists('path', $url) ? $url['path'] : '/';
     }
     if (!array_key_exists('Host', $packet)) {
         $packet['Host'] = 'localhost';
     }
     $port = array_key_exists('Port', $packet) ? array_get_unset($packet, 'Port') : '80';
     if (!str_contains(':', $packet['Host'])) {
         $host = $packet['Host'];
         $packet['Host'] = "{$host}:{$port}";
     } else {
         $host = array_shift(explode(':', $packet['Host']));
     }
     $ret = '';
     switch (array_get_unset($packet, 'Scheme')) {
         case 'http':
             $data = http_assemble($packet);
             $address = gethostbyname($host);
             $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
             debug_enforce(false !== $socket);
             $result = socket_connect($socket, $address, intval($port));
             debug_enforce(false !== $result);
             debug_enforce(false !== socket_write($socket, $data, strlen($data)));
             while ($out = socket_read($socket, 2048)) {
                 $ret .= $out;
             }
             socket_close($socket);
             $needle = "\r\n\r\n";
             $ret = substr($ret, strpos($ret, $needle) + strlen($needle));
             break;
         case 'https':
             $data = http_assemble($packet);
             $socket = fsockopen('tls://' . $host, $port, $errno, $errstr);
             debug_enforce($socket !== false, 'Cannot open socket to ' . var_dump_human_compact('tls://' . $host));
             debug_enforce(strlen($data) === fwrite($socket, $data));
             while (!feof($socket)) {
                 $ret .= fgets($socket);
             }
             fclose($socket);
             $response = http_response_deassemble($ret);
             $ret = array_get($response, 'Content');
             break;
         default:
             debug_enforce(false, 'Unknown scheme');
             break;
     }
     return $ret;
 }