Example #1
0
 /**
  * 接続する
  * @param string $address
  * @param integer $port
  * @param integer $timeout
  * @return boolean
  */
 public function connect($address = null, $port = null, $timeout = null)
 {
     if ($this->is_connected()) {
         throw new \RuntimeException(sprintf("socket has already connected to server [%s:%s]", $this->hotname, $this->port));
     }
     if ($address) {
         $this->address = $address;
     }
     if ($port) {
         $this->port = $port;
     }
     if ($timeout) {
         $this->timeout = $timeout;
     }
     try {
         $this->_resource_ = fsockopen($this->address, $this->port, $errno, $errstr, $this->timeout);
     } catch (\Exception $e) {
         \org\rhaco\Log::error($e->getMessage());
     }
     if (!is_resource($this->_resource_)) {
         \org\rhaco\Log::error(sprintf("failed to connect server [%s:%s]", $this->address, $this->port));
         return false;
     }
     return true;
 }
Example #2
0
 /**
  * 作成
  * @param string $package モデル名
  * @automap @['post_after'=>['save_and_add_another'=>['do_create','package'],'save'=>['do_find','package']]]
  */
 public function do_create($package)
 {
     if ($this->is_post()) {
         try {
             $obj = $this->get_model($package, false);
             $obj->set_props($this);
             $obj->save();
         } catch (\Exception $e) {
             \org\rhaco\Log::error($e);
         }
     } else {
         $obj = $this->get_model($package, false);
     }
     $this->vars('model', $obj);
     $this->vars('package', $package);
 }
Example #3
0
 private function exec($_src_)
 {
     /**
      * 実行前処理
      * @param org.rhaco.lang.Str $obj
      */
     $this->object_module('before_exec_template', \org\rhaco\lang\Str::ref($_obj_, $_src_));
     foreach ($this->default_vars() as $k => $v) {
         $this->vars($k, $v);
     }
     ob_start();
     if (is_array($this->vars) && !empty($this->vars)) {
         extract($this->vars);
     }
     eval('?><?php $_display_exception_=' . (\org\rhaco\Conf::get('display_exception') === true ? 'true' : 'false') . '; ?>' . (string) $_obj_);
     $_eval_src_ = ob_get_clean();
     if (strpos($_eval_src_, 'Parse error: ') !== false) {
         if (preg_match("/Parse error\\:(.+?) in .+eval\\(\\)\\'d code on line (\\d+)/", $_eval_src_, $match)) {
             list($msg, $line) = array(trim($match[1]), (int) $match[2]);
             $lines = explode("\n", $_src_);
             $plrp = substr_count(implode("\n", array_slice($lines, 0, $line)), "<?php 'PLRP'; ?>\n");
             \org\rhaco\Log::error($msg . ' on line ' . ($line - $plrp) . ' [compile]: ' . trim($lines[$line - 1]));
             $lines = explode("\n", $this->selected_src);
             \org\rhaco\Log::error($msg . ' on line ' . ($line - $plrp) . ' [plain]: ' . trim($lines[$line - 1 - $plrp]));
             if (\org\rhaco\Conf::get('display_exception') === true) {
                 $_eval_src_ = $msg . ' on line ' . ($line - $plrp) . ': ' . trim($lines[$line - 1 - $plrp]);
             }
         }
     }
     $_src_ = $this->selected_src = null;
     /**
      * 実行後処理
      * @param org.rhaco.lang.Str $obj
      */
     $this->object_module('after_exec_template', \org\rhaco\lang\Str::ref($_obj_, $_eval_src_));
     return (string) $_obj_;
 }