當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TimberHelper::transient方法代碼示例

本文整理匯總了PHP中TimberHelper::transient方法的典型用法代碼示例。如果您正苦於以下問題:PHP TimberHelper::transient方法的具體用法?PHP TimberHelper::transient怎麽用?PHP TimberHelper::transient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TimberHelper的用法示例。


在下文中一共展示了TimberHelper::transient方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: is_home

<?php

/**
 * @package  WordPress
 * @subpackage  Timber
 * @since   Timber 0.1
 */
if (!class_exists('Timber')) {
    echo 'Timber not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>';
    return;
}
$context = Timber::get_context();
$context['post'] = Timber::get_post();
$context['is_home'] = is_home() || is_front_page();
if ($context['is_home']) {
    $context['site_css_contents'] = TimberHelper::transient('site_css_contents', function () {
        return file_get_contents(get_template_directory_uri() . "/assets/dist/css/application.min.css");
    }, 14400);
}
$templates = array('home.twig');
Timber::render($templates, $context);
開發者ID:leroyg,項目名稱:launchframe,代碼行數:21,代碼來源:front-page.php

示例2: testTransientAsString

 function testTransientAsString()
 {
     $transient = TimberHelper::transient('jn_test_string', 'my_test_callback', 200);
     $this->assertEquals($transient, 'lbj');
 }
開發者ID:pedrokoblitz,項目名稱:centro-dialogo-aberto,代碼行數:5,代碼來源:test-timber-cache.php

示例3: testExpireTransient

 function testExpireTransient()
 {
     $transient = $this->_generate_transient_name();
     $first_value = TimberHelper::transient($transient, function () {
         return 'first_value';
     }, 2);
     sleep(3);
     $second_value = TimberHelper::transient($transient, function () {
         return 'second_value';
     }, 2);
     $this->assertEquals('second_value', $second_value);
 }
開發者ID:Butterwell,項目名稱:timber,代碼行數:12,代碼來源:test-timber-cache.php

示例4: TimberPost

 * @since Boilerplate 1.0
 */
$data = Timber::get_context();
$pi = new TimberPost();
$data['post'] = $pi;
$data['body_class'] .= ' page-' . $pi->post_name;
$template_file = 'page.twig';
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $data['theme_dir'] . '/css/' . $pi->post_type . '-' . $post->post_name . '.css')) {
    $data['post']->css_file = $data['theme_dir'] . '/css/' . $pi->post_type . '-' . $post->post_name . '.css';
}
$contribs = TimberHelper::transient('timber-contribs', function () {
    require_once __DIR__ . '/vendor/tan-tan-kanarek/github-php-client/tan-tan-kanarek/github-php-client/client/GitHubClient.php';
    $client = new GitHubClient();
    $auth = file_get_contents(__DIR__ . '/auth.json');
    $auth = json_decode($auth);
    $client->setCredentials($auth->github->user, $auth->github->pass);
    $contribs = $client->repos->listContributors('jarednova', 'timber', array('per_page' => 100));
    $extra = count($contribs) % 6;
    $total = count($contribs) - $extra;
    $contribs = TimberHelper::array_truncate($contribs, $total);
    $ret = array();
    foreach ($contribs as $contrib) {
        $obj = new stdClass();
        $obj->login = $contrib->getLogin();
        $obj->avatar_url = $contrib->getAvatarUrl();
        $ret[] = $obj;
    }
    return $ret;
}, 1200);
$data['contribs'] = $contribs;
Timber::render(array('custom/page-' . $pi->post_name . '.twig', 'page-' . $pi->post_name . '.twig', 'page.twig'), $data);
開發者ID:ramsaylanier,項目名稱:blades,代碼行數:31,代碼來源:page-timber.php


注:本文中的TimberHelper::transient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。