示例#1
0
文件: Storage.php 项目: lev1976g/core
 public function get($key)
 {
     $object = $this->db->select('*')->from(':cache')->where(['file_name' => $key])->get();
     if (isset($object['cache_id'])) {
         return $this->_build($object);
     }
     return null;
 }
示例#2
0
 public function export()
 {
     $zipFile = PHPFOX_DIR_FILE . 'static/' . $this->folder . '.zip';
     if (file_exists($zipFile)) {
         unlink($zipFile);
     }
     if (file_exists($zipFile . '.json')) {
         unlink($zipFile . '.json');
     }
     $export = ['name' => $this->name, 'created' => $this->created, 'flavors' => [], 'files' => []];
     $flavors = $this->_db->select('*')->from(':theme_style')->where(['theme_id' => $this->theme_id])->all();
     foreach ($flavors as $flavor) {
         $export['flavors'][$flavor['style_id']] = $flavor['name'];
     }
     $files = \Phpfox_File::instance()->getAllFiles($this->getPath());
     foreach ($files as $file) {
         $name = str_replace($this->getPath(), '', $file);
         $export['files'][$name] = file_get_contents($file);
         // p($name);
     }
     // d($export);
     file_put_contents($zipFile . '.json', json_encode($export, JSON_PRETTY_PRINT));
     chdir(PHPFOX_DIR_FILE . 'static/');
     $Zip = new \ZipArchive();
     $Zip->open($zipFile, \ZipArchive::CREATE);
     $Zip->addFile($this->folder . '.zip.json');
     $Zip->close();
     unlink($zipFile . '.json');
     $name = \Phpfox_Parse_Input::instance()->cleanFileName($this->name);
     \Phpfox_File::instance()->forceDownload($zipFile, 'phpfox-theme-' . $name . '.zip');
     exit;
 }
示例#3
0
 /**
  * 查询数据
  *
  * @param array $fields 查询字段
  * @param array $filter 查询条件
  * @param array $order 排序条件
  * @param int $limit 查询数量
  * @param int $offset 偏移量
  * @return array
  */
 public function select(array $fields = null, array $filter = null, array $order = null, $limit = 0, $offset = 0)
 {
     $fields = empty($fields) ? '*' : implode(',', $fields);
     $sql = "SELECT {$fields} FROM {$this->tableName}";
     if (!empty($filter)) {
         $sql .= " WHERE " . $this->parseFilter($filter);
     }
     if (!empty($order)) {
         $orderSql = array();
         foreach ($order as $key => $val) {
             $orderSql[] = "{$key} " . (strtolower($val) == 'asc' ? 'ASC' : 'DESC');
         }
         $sql .= " ORDER BY " . implode(', ', $orderSql);
     }
     if ($limit > 0) {
         $sql .= $offset > 0 ? " LIMIT {$offset}, {$limit}" : " LIMIT {$limit}";
     }
     return $this->db->select($sql);
 }