本文整理汇总了PHP中Versioned::choose_site_stage方法的典型用法代码示例。如果您正苦于以下问题:PHP Versioned::choose_site_stage方法的具体用法?PHP Versioned::choose_site_stage怎么用?PHP Versioned::choose_site_stage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Versioned
的用法示例。
在下文中一共展示了Versioned::choose_site_stage方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preRequest
public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
{
// Bootstrap session so that Session::get() accesses the right instance
$dummyController = new Controller();
$dummyController->setSession($session);
$dummyController->setRequest($request);
$dummyController->pushCurrent();
// Block non-authenticated users from setting the stage mode
if (!Versioned::can_choose_site_stage($request)) {
$permissionMessage = sprintf(_t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", 'You must log in with your CMS password in order to view the draft or archived content. ' . '<a href="%s">Click here to go back to the published site.</a>'), Convert::raw2xml(Controller::join_links(Director::baseURL(), $request->getURL(), "?stage=Live")));
// Force output since RequestFilter::preRequest doesn't support response overriding
$response = Security::permissionFailure($dummyController, $permissionMessage);
$session->inst_save();
$dummyController->popCurrent();
// Prevent output in testing
if (class_exists('SapphireTest', false) && SapphireTest::is_running_test()) {
throw new SS_HTTPResponse_Exception($response);
}
$response->output();
die;
}
Versioned::choose_site_stage();
$dummyController->popCurrent();
return true;
}
示例2: setUp
protected function setUp()
{
$config = \Config::inst();
$config->update('Director', 'environment_type', 'dev');
$config->update('SSViewer', 'theme', 'theme');
\Versioned::choose_site_stage();
$this->controllerMock = $this->getMock('Controller');
$this->keyCreator = new ControllerBased($this->controllerMock);
}
示例3: start
/**
|--------------------------------------------------------------------------
| Start up Silverstripe
|--------------------------------------------------------------------------
|
| Include Silverstripe's core code and connect it to its database
|
*/
public static function start()
{
if (!static::$started) {
static::$started = true;
require_once 'SilverstripeHelpers.php';
if (true !== (require_once public_path() . '/silverstripe/framework/core/Core.php')) {
require_once public_path() . '/silverstripe/framework/model/DB.php';
global $databaseConfig;
if (!\DB::isActive()) {
\DB::connect($databaseConfig);
}
}
\Versioned::choose_site_stage();
}
}
示例4: init
public function init()
{
if ($this->getSession() && $this->data()->exists()) {
Versioned::choose_site_stage($this->getSession());
} else {
Versioned::reading_stage('Live');
}
parent::init();
self::include_microblog_requirements();
$member = $this->securityContext->getMember();
if ($member && $member->ID) {
if ($member->Balance < self::POOR_USER_THRESHOLD) {
throw new Exception("Broken pipe");
}
}
}
示例5: testReadingPersistent
/**
* Tests that reading mode persists between requests
*/
public function testReadingPersistent()
{
$session = Injector::inst()->create('Session', array());
// Set to stage
Director::test('/?stage=Stage', null, $session);
$this->assertEquals('Stage.Stage', $session->inst_get('readingMode'), 'Check querystring changes reading mode to Stage');
Director::test('/', null, $session);
$this->assertEquals('Stage.Stage', $session->inst_get('readingMode'), 'Check that subsequent requests in the same session remain in Stage mode');
// Test live persists
Director::test('/?stage=Live', null, $session);
$this->assertEquals('Stage.Live', $session->inst_get('readingMode'), 'Check querystring changes reading mode to Live');
Director::test('/', null, $session);
$this->assertEquals('Stage.Live', $session->inst_get('readingMode'), 'Check that subsequent requests in the same session remain in Live mode');
// Test that session doesn't redundantly store the default stage if it doesn't need to
$session2 = Injector::inst()->create('Session', array());
Director::test('/', null, $session2);
$this->assertEmpty($session2->inst_changedData());
Director::test('/?stage=Live', null, $session2);
$this->assertEmpty($session2->inst_changedData());
// Test choose_site_stage
Session::set('readingMode', 'Stage.Stage');
Versioned::choose_site_stage();
$this->assertEquals('Stage.Stage', Versioned::get_reading_mode());
Session::set('readingMode', 'Archive.2014-01-01');
Versioned::choose_site_stage();
$this->assertEquals('Archive.2014-01-01', Versioned::get_reading_mode());
Session::clear('readingMode');
Versioned::choose_site_stage();
$this->assertEquals('Stage.Live', Versioned::get_reading_mode());
}
示例6: testStageQuerying
public function testStageQuerying()
{
Injector::inst()->registerService(new SolrSearchService());
// we should be able to perform a query for documents with 'text content'
// and receive back some valid data
$search = singleton('SolrSearchService');
if (!$search->isConnected()) {
return;
}
// clear everything out, then index content
/* @var $search SolrSearchService */
$search->getSolr()->deleteByQuery('*:*');
$item = $this->objFromFixture('Page', 'home');
$item->write();
$item->doPublish();
$results = $search->query('title:home');
$objects = $results->getDataObjects();
// there should actually be two results; one for each stage.
$this->assertEquals(2, $objects->count());
// now set a stage
Versioned::choose_site_stage();
$results = $search->query('title:home');
$objects = $results->getDataObjects();
$this->assertEquals(1, $objects->count());
}
示例7: init
public function init()
{
Versioned::choose_site_stage();
parent::init();
}
示例8: preRequest
public function preRequest()
{
Versioned::choose_site_stage();
}
示例9: preRequest
/**
* If this url allows caching and there is a cached response then send it
* @param SS_HTTPRequest $request
* @param Session $session
* @param DataModel $model
* @return bool|void
*/
public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
{
if ($this->allowFetch($request)) {
\Versioned::choose_site_stage();
if ($request->getURL() == '') {
$request = clone $request;
$request->setUrl('home');
}
$response = $this->cache->get($this->name, \Injector::inst()->create('CacheIncludeKeyCreator', $this->getController($request)));
if ($response instanceof SS_HTTPResponse) {
// replace in body
if ($this->hasTokens()) {
$body = $response->getBody();
foreach ($this->tokens as $token) {
$name = self::REPLACED_TOKEN_PREFIX . $token->getName();
if (strpos($body, $name) !== false) {
$body = str_replace($name, $token->getValue(), $body);
}
}
$response->setBody($body);
}
$session->save();
$response->output();
exit;
}
}
return true;
}
示例10: preRequest
public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
{
Versioned::choose_site_stage($session);
return true;
}