コード例 #1
0
ファイル: Dt.php プロジェクト: tokushima/rhaco3
 protected function __init__()
 {
     $name = $summary = $description = null;
     $d = debug_backtrace(false);
     $d = array_pop($d);
     $this->vars('app_mode', \org\rhaco\Conf::appmode());
     $this->vars('f', new Dt\Helper());
     $this->vars('has_coverage', function_exists('xdebug_get_code_coverage'));
     $this->vars('has_test', is_dir(getcwd() . '/test'));
     $this->vars('media_url', \org\rhaco\net\Path::slash(\org\rhaco\Conf::get('media_url'), null, false));
 }
コード例 #2
0
ファイル: File.php プロジェクト: tokushima/rhaco3
 private function base()
 {
     $base = Path::slash(\org\rhaco\Conf::get('document_root'), null, true);
     return $base . Path::slash($this->map_arg('path'), null, true);
 }
コード例 #3
0
ファイル: Flow.php プロジェクト: tokushima/rhaco3
 private function print_template($template_path, $template, $media_url, $put_block, $obj, $apps, $index, $path_replace = true)
 {
     if ($path_replace) {
         if (isset($apps[$index]['media_path'])) {
             $media_url = $media_url . \org\rhaco\net\Path::slash($apps[$index]['media_path'], true, false);
         }
         if (isset($apps[$index]['template_path'])) {
             $template_path = $template_path . \org\rhaco\net\Path::slash($apps[$index]['template_path'], false, true);
         }
     }
     if (!empty($put_block)) {
         $this->template->put_block(\org\rhaco\net\Path::absolute($this->template_path, $put_block));
     }
     if (isset($apps[$index]['template_super'])) {
         $this->template->template_super($this->template_path . $apps[$index]['template_super']);
     }
     if (is_array($obj) && isset($obj[0]) && isset($obj[1])) {
         foreach (is_array($obj[1]) ? $obj[1] : array($obj[1]) as $o) {
             $this->template->set_object_module($o);
         }
         $obj = $obj[0];
     }
     $this->template->media_url($media_url);
     $this->template->cp($obj);
     if (isset($apps[$index]['vars'])) {
         $this->template->cp($apps[$index]['vars']);
     }
     $this->template->vars('t', new \org\rhaco\flow\module\Helper($this->app_url, $media_url, $apps[$index]['name'], $apps[$index]['num'], $this->entry_file(), $apps, $obj));
     $src = $this->template->read(\org\rhaco\net\Path::absolute($template_path, $template));
     /**
      * テンプレートの出力
      * @param org.rhaco.lang.Str $obj
      */
     $this->object_module('before_flow_print_template', \org\rhaco\lang\Str::ref($obj, $src));
     $src = (string) $obj;
     header('Content-Length: ' . strlen($src));
     print $src;
     exit;
 }
コード例 #4
0
ファイル: Storage.php プロジェクト: tokushima/rhaco3
 /**
  * ファイルの実際のパスを返す
  * @conf string $base_path ストレージのベースパス
  * @param string $path ベースパスからの相対パス
  * @return string
  */
 public static function get_path($path)
 {
     $base_path = \org\rhaco\Conf::get('base_path');
     if (empty($base_path)) {
         throw new \org\rhaco\io\Storage\StorageException('ベースパスが指定されていません');
     }
     return \org\rhaco\net\Path::absolute(\org\rhaco\net\Path::slash($base_path, null, true), $path);
 }
コード例 #5
0
ファイル: Runserver.php プロジェクト: tokushima/rhaco3
 /**
  * @module org.rhaco.net.listener.SocketListener
  * @param org.rhaco.net.listener.Channel $channel
  */
 public function connect($channel)
 {
     $head = $body = null;
     $method = $uri = $query = $boundary = null;
     $POST = $GET = $FILES = $SERVER = array();
     $message_len = $null_cnt = 0;
     try {
         $uid = uniqid('');
         while (true) {
             $message = $channel->read();
             if ($message === '') {
                 $null_cnt++;
             }
             if ($null_cnt > 5) {
                 break;
             }
             if ($method === null) {
                 $head .= $message;
                 if (substr($head, -4) === "\r\n\r\n") {
                     $lines = explode("\n", trim($head));
                     if (!empty($lines)) {
                         $exp = explode(' ', array_shift($lines));
                         if (sizeof($exp) >= 2) {
                             list($method, $uri) = $exp;
                         }
                         if (strpos($uri, '?')) {
                             list($uri, $SERVER['QUERY_STRING']) = explode('?', $uri);
                             parse_str($SERVER['QUERY_STRING'], $GET);
                         }
                         foreach ($lines as $line) {
                             $exp = explode(':', $line, 2);
                             if (sizeof($exp) == 2) {
                                 list($name, $value) = $exp;
                                 $SERVER['HTTP_' . str_replace(array('-'), array('_'), strtoupper(trim($name)))] = trim($value);
                             }
                         }
                     }
                     if ($method === null || $method == 'GET') {
                         break;
                     }
                     if (isset($SERVER['HTTP_CONTENT_TYPE']) && preg_match("/multipart\\/form-data; boundary=(.+)\$/", $SERVER['HTTP_CONTENT_TYPE'], $m)) {
                         $boundary = '--' . $m[1];
                     }
                 }
             } else {
                 if ($method == 'POST') {
                     $message_len += strlen($message);
                     $body .= $message;
                     if (isset($SERVER['HTTP_CONTENT_LENGTH']) && $message_len >= $SERVER['HTTP_CONTENT_LENGTH'] || !isset($SERVER['HTTP_CONTENT_LENGTH']) && substr($body, -4) === "\r\n\r\n") {
                         if (isset($boundary)) {
                             list($body) = explode($boundary . "--\r\n", $body, 2);
                             foreach (explode($boundary . "\r\n", $body) as $k => $block) {
                                 if (!empty($block)) {
                                     list($h, $b) = explode("\r\n\r\n", $block);
                                     list($b) = explode("\r\n", $b, 2);
                                     if (preg_match("/\\sname=([\"'])(.+?)\\1/", $h, $m)) {
                                         $name = $m[2];
                                         if (preg_match("/filename=([\"'])(.+?)\\1/", $h, $m)) {
                                             $tmp_name = self::work_path($uid, $k);
                                             \org\rhaco\io\File::write($tmp_name, $b);
                                             $FILES[$name] = array('name' => $m[2], 'tmp_name' => $tmp_name, 'size' => filesize($tmp_name), 'error' => 0);
                                         } else {
                                             $POST[$name] = $b;
                                         }
                                     }
                                 }
                             }
                         } else {
                             parse_str($body, $POST);
                         }
                         break;
                     } else {
                         if (!isset($SERVER['HTTP_CONTENT_LENGTH'])) {
                             break;
                         }
                     }
                 } else {
                     $this->output('Unknown method: ' . $method);
                     break;
                 }
             }
         }
         if (!empty($uri)) {
             $request_uri = $uri;
             $this->output('request uri: ' . $uri);
             $uri = preg_replace("/\\/+/", "/", $uri);
             $uri_path = \org\rhaco\net\Path::absolute(getcwd(), \org\rhaco\net\Path::slash($uri, false, null));
             if (strpos($uri, '.php') === false && !is_file($uri_path) && $uri != '/favicon.ico') {
                 $exp = explode('/', \org\rhaco\net\Path::slash($uri, false, null), 2);
                 if (is_file(\org\rhaco\net\Path::absolute(getcwd(), $exp[0] . '.php')) && isset($exp[1])) {
                     $uri = '/' . $exp[0] . '.php/' . $exp[1];
                 } else {
                     if (is_file(\org\rhaco\net\Path::absolute(getcwd(), 'index.php'))) {
                         $uri = '/index.php' . $uri;
                     }
                 }
             }
             if ($request_uri != $uri) {
                 $this->output(' - rewrite uri: ' . $uri);
             }
             if (strpos($uri, '.php/') !== false) {
                 $exp = explode('.php/', $uri, 2);
                 $uri = $exp[0] . '.php';
                 $SERVER['PATH_INFO'] = '/' . $exp[1];
             }
             $path = \org\rhaco\net\Path::absolute(getcwd(), \org\rhaco\net\Path::slash($uri, false, null));
             if (is_file($path)) {
                 $file = new \org\rhaco\io\File($path);
                 if (substr($path, -4) == '.php') {
                     $file->mime('text/html');
                 }
                 $headers = array();
                 $headers[] = 'Content-Type: ' . $file->mime();
                 $headers[] = 'Connection: close';
                 if (substr($path, -4) == '.php') {
                     $SERVER['REQUEST_METHOD'] = $method;
                     $REQUEST = array('_SERVER' => $SERVER, '_POST' => $POST, '_GET' => $GET, '_FILES' => $FILES);
                     \org\rhaco\io\File::write(self::work_path($uid, 'request'), serialize($REQUEST));
                     $exec_command = $this->php_cmd . ' ' . $file->fullname() . ' -emulator ' . $uid;
                     $this->output(' -- ' . $exec_command);
                     $cmd = new \org\rhaco\Command($exec_command);
                     if (is_file(self::work_path($uid, 'header'))) {
                         $send_header = unserialize(\org\rhaco\io\File::read(self::work_path($uid, 'header')));
                         if (!empty($send_header) && is_array($send_header)) {
                             $headers = array_merge($headers, $send_header);
                         }
                     }
                     foreach ($headers as $k => $v) {
                         if (strpos($v, ':') === false) {
                             $top = $headers[$k];
                             unset($headers[$k]);
                             array_unshift($headers, $top);
                             break;
                         }
                     }
                     $output_header = trim(implode("\r\n", $headers));
                     if (strpos($output_header, 'HTTP/') !== 0) {
                         if (strpos($output_header, 'Location: ') !== false) {
                             $output_header = "HTTP/1.1 302 Found\r\n" . $output_header;
                         } else {
                             $output_header = "HTTP/1.1 200 OK\r\n" . $output_header;
                         }
                     }
                     $channel->write($output_header . "\r\n\r\n");
                     $channel->write($cmd->stdout());
                     \org\rhaco\io\File::rm(self::work_path($uid));
                 } else {
                     $channel->write("HTTP/1.1 200 OK\r\n" . implode("\r\n", $headers) . "\r\n\r\n");
                     $fp = fopen($file->fullname(), 'rb');
                     while (!feof($fp)) {
                         $channel->write(fread($fp, 4096));
                     }
                     fclose($fp);
                 }
             } else {
                 $this->output($path . ' not found');
                 $channel->write($this->error(404, 'Not Found', 'The requested URL ' . $uri . ' was not found on this server.'));
             }
         }
     } catch (\org\rhaco\net\listener\exception\ErrorException $e) {
         $this->output($e->getMessage());
     }
 }
コード例 #6
0
ファイル: slash.php プロジェクト: tokushima/rhaco3
<?php

eq("/abc/", \org\rhaco\net\Path::slash("/abc/", null, null));
eq("/abc/", \org\rhaco\net\Path::slash("abc", true, true));
eq("/abc/", \org\rhaco\net\Path::slash("/abc/", true, true));
eq("abc/", \org\rhaco\net\Path::slash("/abc/", false, true));
eq("/abc", \org\rhaco\net\Path::slash("/abc/", true, false));
eq("abc", \org\rhaco\net\Path::slash("/abc/", false, false));