예제 #1
0
파일: Sqlite.php 프로젝트: tokushima/rhaco3
 /**
  * @module org.rhaco.store.db.Dbc
  * @param string $name
  * @param string $host
  * @param number $port
  * @param string $user
  * @param string $password
  * @param string $sock
  * @param boolean $autocommit
  * @see org\rhaco\store\db\module.Base::connect()
  */
 public function connect($name, $host, $port, $user, $password, $sock, $autocommit)
 {
     if (!extension_loaded('pdo_sqlite')) {
         throw new \RuntimeException('pdo_sqlite not supported');
     }
     $con = $path = null;
     if (empty($host)) {
         $host = \org\rhaco\Conf::get('host');
         if (empty($host)) {
             $host = empty($name) ? ':memory:' : getcwd();
         }
     }
     if ($host != ':memory:') {
         $host = str_replace('\\', '/', $host);
         if (substr($host, -1) != '/') {
             $host = $host . '/';
         }
         $path = \org\rhaco\net\Path::absolute($host, $name);
         \org\rhaco\io\File::mkdir(dirname($path));
     }
     try {
         $con = new \PDO(sprintf('sqlite:%s', $host == ':memory:' ? ':memory:' : $host . $name));
     } catch (\PDOException $e) {
         throw new \org\rhaco\store\db\exception\ConnectionException($e->getMessage());
     }
     return $con;
 }
예제 #2
0
파일: File.php 프로젝트: tokushima/rhaco3
 private static function path($dir = null)
 {
     if ($dir === null) {
         $dir = \org\rhaco\Conf::get('path', \org\rhaco\io\File::work_path('templates'));
     }
     if (substr(str_replace("\\", '/', $dir), -1) == '/') {
         $dir = subustr($dir, 0, -1);
     }
     \org\rhaco\io\File::mkdir($dir, 0777);
     return $dir;
 }
예제 #3
0
 /**
  * ランダムなノードのパスを返す
  * ディレクトリが存在しなかった場合はディレクトリを作成する
  * @param string $type
  * @return string ノード/サービス名/タイプ/Y/md/H
  */
 public static function get_save_path($type = 'mixed')
 {
     $nodes = \org\rhaco\Conf::get('save_nodes');
     if (empty($nodes)) {
         throw new \org\rhaco\io\Storage\StorageException('ノードが設定されていません');
     }
     $service = \org\rhaco\Conf::get('service_name', 'new_service');
     $dir = \org\rhaco\net\Path::slash($nodes[rand(1, sizeof($nodes)) - 1], false, true) . $service . '/' . $type . '/' . date('Y/md/H');
     \org\rhaco\io\File::mkdir(self::get_path($dir), 0777);
     return $dir;
 }
예제 #4
0
파일: Image.php 프로젝트: tokushima/rhaco3
 /**
  * ファイルに出力する
  * @param string $filename
  * @param string $type
  * @return string
  */
 public function write($filename, $type = null)
 {
     if (!is_dir(dirname($filename))) {
         \org\rhaco\io\File::mkdir(dirname($filename));
     }
     if ($type !== null) {
         $this->type($type);
     }
     $bool = false;
     $ext = image_type_to_extension($this->type_no(), true);
     if ($ext == '.jpeg') {
         $ext = '.jpg';
     }
     if (!preg_match('/' . preg_quote($ext) . '$/i', $filename)) {
         $filename = $filename . $ext;
     }
     switch ($this->type) {
         case 'gif':
             $bool = imagegif($this->resource, $filename);
             break;
         case 'jpg':
             $bool = imagejpeg($this->resource, $filename, ceil($this->quality * 10));
             break;
         case 'png':
             $bool = imagepng($this->resource, $filename, 10 - ceil($this->quality));
             break;
         case 'bmp':
             $bool = imagewbmp($this->resource, $filename);
             break;
     }
     if (!$bool) {
         throw new Image\ImageException('invalid type');
     }
     return $filename;
 }
예제 #5
0
 /**
  * 添付ファイルを移動します
  * @param array $file_info
  * @param string $newname
  */
 public function move_file($file_info, $newname)
 {
     if (!$this->has_file($file_info)) {
         throw new \LogicException('file not found ');
     }
     if (!is_dir(dirname($newname))) {
         \org\rhaco\io\File::mkdir(dirname($newname));
     }
     copy($file_info['tmp_name'], $newname);
     chmod($newname, 0777);
     unlink($file_info['tmp_name']);
 }
예제 #6
0
 public static function unzip($inpath, $outpath)
 {
     if (substr($outpath, -1) != '/') {
         $outpath = $outpath . '/';
     }
     if (!is_dir($outpath)) {
         \org\rhaco\io\File::mkdir($outpath, 0777);
     }
     $zip = new \ZipArchive();
     if ($zip->open($inpath) !== true) {
         throw new \ErrorException('failed to open stream');
     }
     $zip->extractTo($outpath);
     $zip->close();
 }