Пример #1
0
 /**
  * @param string $name
  * @param string $host
  * @param number $port
  * @param string $user
  * @param string $password
  * @param string $sock
  * @param boolean $autocommit
  */
 public function connect($name, $host, $port, $user, $password, $sock, $autocommit)
 {
     unset($port, $user, $password, $sock);
     if (!extension_loaded('pdo_sqlite')) {
         throw new \ebi\exception\ConnectionException('pdo_sqlite not supported');
     }
     $con = null;
     if (empty($name)) {
         $name = getcwd() . '/data.sqlite3';
     }
     if ($host != ':memory:') {
         if (strpos($name, '.') === false) {
             $name = $name . '.sqlite3';
         }
         $host = str_replace('\\', '/', $host);
         if (substr($host, -1) != '/') {
             $host = $host . '/';
         }
         $path = \ebi\Util::path_absolute($host, $name);
         \ebi\Util::mkdir(dirname($path));
     }
     try {
         $con = new \PDO(sprintf('sqlite:%s', $host == ':memory:' ? ':memory:' : $path));
         $con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     } catch (\PDOException $e) {
         throw new \ebi\exception\ConnectionException($e->getMessage());
     }
     if (!empty($this->timezone)) {
         $this->timezone_offset = (new \DateTimeZone($this->timezone))->getOffset(new \DateTime('now', new \DateTimeZone('UTC')));
     }
     return $con;
 }
Пример #2
0
<?php

/**
 * Install of testman
 */
$path = getcwd();
if (!is_file($f = $path . '/test/testman.phar')) {
    \ebi\Util::mkdir($path . '/test');
    file_put_contents($f = $path . '/test/testman.phar', file_get_contents('http://git.io/testman.phar'));
    \cmdman\Std::println_success('Created ' . $f);
}
if (!is_file($f = $path . '/test/testman.settings.php')) {
    file_put_contents($f, <<<'_C'
<?php
\ebi\Conf::set(ebi.Db::class,'autocommit',true);
\testman\Conf::set('urls',\ebi\Dt::get_urls());
_C
);
    \cmdman\Std::println_success('Created ' . $f);
}
if (!is_file($f = $path . '/test/testman.fixture.php')) {
    file_put_contents($f, <<<'_C'
<?php
_C
);
    \cmdman\Std::println_success('Created ' . $f);
}
if (!is_file($f = $path . '/test/__setup__.php')) {
    file_put_contents($f, <<<'_C'
<?php
\ebi\Exceptions::clear();
Пример #3
0
 /**
  * zipを解凍してファイル書き出しを行う
  * @param string $zipfile 解凍するZIPファイル
  * @param string $outpath 解凍先のファイルパス
  */
 public static function unzip($zipfile, $outpath)
 {
     $zip = new \ZipArchive();
     if ($zip->open($zipfile) !== true) {
         throw new \ebi\exception\InvalidArgumentException('failed to open stream');
     }
     if (substr($outpath, -1) != '/') {
         $outpath = $outpath . '/';
     }
     if (!is_dir($outpath)) {
         \ebi\Util::mkdir($outpath, 0777);
     }
     $zip->extractTo($outpath);
     $zip->close();
 }
Пример #4
0
 /**
  * 添付ファイルを移動します
  * @param array $file_info
  * @param string $newname
  */
 public function move_file($file_info, $newname)
 {
     if (is_string($file_info)) {
         $file_info = $this->in_files($file_info);
     }
     if (!$this->has_file($file_info)) {
         throw new \ebi\exception\NotFoundException('file not found ');
     }
     if (!is_dir(dirname($newname))) {
         \ebi\Util::mkdir(dirname($newname));
     }
     \ebi\Util::copy($file_info['tmp_name'], $newname);
     \ebi\Util::rm($file_info['tmp_name']);
 }