Beispiel #1
0
/**
 * 缓存管理
 * @param mixed $name 缓存名称,如果为数组表示进行缓存设置
 * @param mixed $value 缓存值
 * @param mixed $options 缓存参数
 * @return mixed
 */
function cache($name, $value = '', $options = null)
{
    static $cache = '';
    if (is_array($options)) {
        // 缓存操作的同时初始化
        $type = isset($options['type']) ? $options['type'] : '';
        $cache = Core\Cache::getInstance($type, $options);
    } elseif (is_array($name)) {
        // 缓存初始化
        $type = isset($name['type']) ? $name['type'] : '';
        $cache = Core\Cache::getInstance($type, $name);
        return $cache;
    } elseif (empty($cache)) {
        // 自动初始化
        $cache = Core\Cache::getInstance();
    }
    if ('' === $value) {
        // 获取缓存
        return $cache->get($name);
    } elseif (is_null($value)) {
        // 删除缓存
        return $cache->rm($name);
    } else {
        // 缓存数据
        if (is_array($options)) {
            $expire = isset($options['expire']) ? $options['expire'] : NULL;
        } else {
            $expire = is_numeric($options) ? $options : NULL;
        }
        return $cache->set($name, $value, $expire);
    }
}
/**
 * 缓存操作
 * @param string $name
 * @param string $value
 */
function cache($name, $value = '')
{
    $cache = Core\Cache::getInstance();
    if (empty($value)) {
        return $cache->get($name);
    } elseif (is_null($value)) {
        return $cache->rm($name);
    } else {
        return $cache->set($name, $value);
    }
}
Beispiel #3
0
 public function testProducerFirst()
 {
     $app = new Core\App();
     $app->link('database', Core\Database::connect());
     $app->link('cachemanager', Core\Cache::init());
     $app->link('success', true);
     Core\Sharer::share('app', $app);
     $test = Core\Sharer::get();
     if ($test['app']->success == true) {
         $this->assertTrue(true);
     } else {
         $this->assertTrue(false);
     }
     $this->assertTrue(true);
     return 'first';
 }
Beispiel #4
0
 public function merge()
 {
     $flavorId = $this->flavor_id;
     $id = $this->theme_id;
     $path = PHPFOX_DIR_SITE . 'themes/' . $id . '/';
     $File = \Phpfox_File::instance();
     $copy = [];
     $dirs = [];
     $files = $File->getAllFiles(PHPFOX_DIR . 'theme/default/');
     foreach ($files as $file) {
         if (!in_array($File->extension($file), ['html', 'js', 'css', 'less'])) {
             continue;
         }
         $parts = pathinfo($file);
         $dirs[] = str_replace(PHPFOX_DIR . 'theme/default/', '', $parts['dirname']);
         $copy[] = $file;
     }
     foreach ($copy as $file) {
         $newFile = $path . str_replace(PHPFOX_DIR . 'theme/default/', '', $file);
         if (in_array($File->extension($file), ['less', 'css'])) {
             $newFile = str_replace('default.' . $File->extension($file), $flavorId . '.' . $File->extension($file), $newFile);
         }
         copy($file, $newFile);
         // p($file . ' -> ' . $newFile);
         if ($File->extension($file) == 'less') {
             $content = file_get_contents($newFile);
             $content = str_replace('../../../', '../../../../PF.Base/', $content);
             file_put_contents($newFile, $content);
         }
     }
     $Db = new \Core\Db();
     $Cache = new \Core\Cache();
     $Db->update(':setting', array('value_actual' => (int) \Phpfox::getParam('core.css_edit_id') + 1), 'var_name = \'css_edit_id\'');
     $Cache->del('setting');
     // exit;
     return true;
 }
Beispiel #5
0
 public function merge()
 {
     $flavorId = $this->flavor_folder;
     if (!$flavorId) {
         throw new \Exception('Cannot merge a theme without a flavor.');
     }
     $id = $this->theme_id;
     //get folder name
     $Db = new \Core\Db();
     $folderName = (string) $Db->select('folder')->from(':theme')->where('theme_id=' . (int) $id)->count();
     if (empty($folderName)) {
         $folderName = $id;
     }
     $path = PHPFOX_DIR_SITE . 'themes/' . $folderName . '/';
     $File = \Phpfox_File::instance();
     $copy = [];
     $dirs = [];
     $themeFile = strtolower($folderName) == 'bootstrap' ? 'bootstrap' : 'default';
     $files = $File->getAllFiles(PHPFOX_DIR . 'theme/' . $themeFile . '/');
     foreach ($files as $file) {
         if (!in_array($File->extension($file), ['html', 'js', 'css', 'less'])) {
             continue;
         }
         $parts = pathinfo($file);
         $dirs[] = str_replace(PHPFOX_DIR . 'theme/default/', '', $parts['dirname']);
         $copy[] = $file;
     }
     foreach ($copy as $file) {
         $newFile = $path . str_replace(PHPFOX_DIR . 'theme/' . $themeFile . '/', '', $file);
         if (in_array($File->extension($file), ['less', 'css'])) {
             $newFile = str_replace('default.' . $File->extension($file), $flavorId . '.' . $File->extension($file), $newFile);
         }
         copy($file, $newFile);
         // p($file . ' -> ' . $newFile);
         if ($File->extension($file) == 'less') {
             $content = file_get_contents($newFile);
             $content = str_replace('../../../', '../../../../PF.Base/', $content);
             file_put_contents($newFile, $content);
         }
     }
     $Cache = new \Core\Cache();
     $Db->update(':setting', array('value_actual' => (int) \Phpfox::getParam('core.css_edit_id') + 1), 'var_name = \'css_edit_id\'');
     $Cache->del('setting');
     // exit;
     return true;
 }
|--------------------------------------------------------------------------
|
| Connect the database for only once. Save the planet.
|
*/
$app->link('database', Core\Database::connect());
/*
|--------------------------------------------------------------------------
| Starting the Caching Engine
|--------------------------------------------------------------------------
|
| This is our favourite part. Minimize the resource usage, maximize our
| capabilities.
|
*/
$app->link('cachemanager', Core\Cache::init());
/*
|--------------------------------------------------------------------------
| Share the Singleton $app with the Template Files
|--------------------------------------------------------------------------
|
| Eliminate complexity, get the job done.
|
*/
Core\Sharer::share('app', $app);
/*
|--------------------------------------------------------------------------
| Dispatch the Router
|--------------------------------------------------------------------------
|
| Ta Da! We can see something now!
Beispiel #7
0
 });
 /**
  * @route /base/popup-output
  * Popup output
  */
 new Core\Route('/popup-output', function (Core\Controller $Controller) use($Base) {
     return $Controller->h1('Hello!', '/base/popup-output')->menu($Base->menu())->render('popup-output.html');
 });
 /**
  * @route /base/comments-and-likes
  * In this example we look into adding Comments & Likes to your items
  */
 new Core\Route('/comments-and-likes', function (Core\Controller $Controller) use($Base) {
     // Load the needed classes
     $ApiFeed = new \Api\Feed();
     $Cache = new \Core\Cache();
     // Check if we cached a feed ID# earlier
     $feedId = $Cache->get('test_feed_id');
     if (!$feedId) {
         // Create a new post
         $feed = $ApiFeed->post(['type_id' => 'PHPfox_Base', 'content' => 'Hello! I am a post.']);
         // Add post to cache so we don't have to create a new post every time
         $Cache->set('test_feed_id', $feed->id);
         $feedId = $feed->id;
     }
     /**
      * Get a feed. When you get a feed it automatically loads the Comment & Like block routine.
      * You just need to output it in the HTML view file using {{ comments() }}
      */
     $ApiFeed->get($feedId);
     return $Controller->title('Comments & Likes')->section('PHPfox App Base', '/base')->h1('Comments & Likes', '/base/comments-and-likes')->menu($Base->menu())->render('comments-and-likes.html');
Beispiel #8
0
 /**
  * Can we delete an object that does not exist?
  *
  * @access public
  */
 public function testRemoveNonExistentObjectFromCache()
 {
     $this->assertFalse(Core\Cache::remove('foobar'));
 }