当前位置: 首页>>代码示例>>PHP>>正文


PHP sfContext::switchTo方法代码示例

本文整理汇总了PHP中sfContext::switchTo方法的典型用法代码示例。如果您正苦于以下问题:PHP sfContext::switchTo方法的具体用法?PHP sfContext::switchTo怎么用?PHP sfContext::switchTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfContext的用法示例。


在下文中一共展示了sfContext::switchTo方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createContextInstance

 protected function createContextInstance($application = 'frontend', $enviroment = 'dev', $debug = true)
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($application, $enviroment, $debug);
     sfContext::createInstance($configuration);
     sfContext::switchTo($application);
     $this->context = sfContext::getInstance();
 }
开发者ID:nvidela,项目名称:kimkelen,代码行数:7,代码来源:AnexaFixClose2015Task.class.php

示例2: setupContext

 /**
  * build new sfContext
  * 
  * @return void
  */
 public function setupContext()
 {
     if (!$this instanceof sfPhpunitContextInitilizerInterface) {
         throw new Exception('You should implement `sfPhpunitContextInitilizerInterface` before initialazing context');
     }
     $app = $this->getApplication();
     $env = $this->getEnvironment();
     $name = $app . '-' . $env;
     if (!sfContext::hasInstance($name)) {
         sfContext::createInstance(ProjectConfiguration::getApplicationConfiguration($app, $env, true), $name);
     }
     sfContext::switchTo($name);
 }
开发者ID:harking,项目名称:sfPhpunitPlugin,代码行数:18,代码来源:sfBasePhpunitTestSuite.class.php

示例3: _initialize

 public function _initialize()
 {
     if (!file_exists('config/ProjectConfiguration.class.php')) {
         throw new \Codeception\Exception\Module('Symfony1', 'config/ProjectConfiguration.class.php not found. This file is required for running symfony1');
     }
     require_once 'config/ProjectConfiguration.class.php';
     $conf = \ProjectConfiguration::getApplicationConfiguration($this->config['app'], 'test', true);
     \sfContext::createInstance($conf, 'default');
     \sfContext::switchTo('default');
     // chdir(\sfConfig::get('sf_web_dir'));
     $this->browser = new \sfBrowser();
     $this->browser->get('/');
     \sfForm::disableCSRFProtection();
 }
开发者ID:NaszvadiG,项目名称:ImageCMS,代码行数:14,代码来源:Symfony1.php

示例4: setUp

 /**
  * setUp method for PHPUnit
  *
  */
 protected function setUp()
 {
     // Here we have to initialize the according context for the test case.
     // As this initialization is quite expensive, the script tries to
     // to do this as rare as possible.
     $app = $this->getApplication();
     if (!sfContext::hasInstance($app)) {
         $configuration = ProjectConfiguration::getApplicationConfiguration($app, $this->getEnvironment(), $this->isDebug());
         sfContext::createInstance($configuration, $app);
         // We have to create a configuration first before the symfony lib is defined.
         // this is the only but ugly chance for including the lime lib correctly
         // without creating a project configuration instance somewhere before
         require_once $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
     }
     // do we have to switch the context?
     if ($app != sfContext::getInstance()->getConfiguration()->getApplication()) {
         sfContext::switchTo($app);
     }
     // autoloading ready, continue
     $this->testBrowser = new sfTestFunctional(new sfBrowser(), $this->getTest());
     $this->_start();
 }
开发者ID:wagnerpinheiro,项目名称:sf-php-unit2plugin,代码行数:26,代码来源:sfPHPUnitBaseFunctionalTestCase.class.php

示例5: executeRemove

 public function executeRemove($request)
 {
     $this->patterns = array();
     if ($request->isMethod('post')) {
         sfContext::switchTo('frontend');
         $frontendContext = sfContext::getInstance();
         if ($page = $request->getParameter('page')) {
             $routing = $frontendContext->getRouting();
             if ($route = $routing->findRoute($page)) {
                 $params = $route['parameters'];
                 $module = $params['module'];
                 $action = $params['action'];
                 unset($params['module']);
                 unset($params['action']);
                 unset($params['sf_culture']);
                 $this->patterns = LsCache::generateCachePatterns($module, $action, $params);
                 LsCache::clearCachePatterns($this->patterns);
             }
         }
         if ($entityId = $request->getParameter('entity_id')) {
             $this->patterns = array_merge($this->patterns, LsCache::clearEntityCacheById($entityId));
         }
         if ($relationshipId = $request->getParameter('relationship_id')) {
             $this->patterns = array_merge($this->patterns, LsCache::clearRelationshipCacheById($relationshipId));
         }
         if ($listId = $request->getParameter('list_id')) {
             $this->patterns = array_merge($this->patterns, LsCache::clearListCacheById($listId));
         }
         if ($userName = $request->getParameter('username')) {
             $this->patterns = array_merge($this->patterns, LsCache::clearUserCacheByName($userName));
         }
         if ($groupName = $request->getParameter('groupname')) {
             $this->patterns = array_merge($this->patterns, LsCache::clearGroupCacheByName($groupName));
         }
         sfContext::switchTo('backend');
     }
 }
开发者ID:silky,项目名称:littlesis,代码行数:37,代码来源:actions.class.php

示例6: stdClass

$frontend_context_prod = sfContext::createInstance(ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false));
$i18n_context = sfContext::createInstance(ProjectConfiguration::getApplicationConfiguration('i18n', 'test', true));
$cache_context = sfContext::createInstance(ProjectConfiguration::getApplicationConfiguration('cache', 'test', true));
// ::getInstance()
$t->diag('::getInstance()');
$t->isa_ok($frontend_context, 'sfContext', '::createInstance() takes an application configuration and returns application context instance');
$t->isa_ok(sfContext::getInstance('frontend'), 'sfContext', '::createInstance() creates application name context instance');
$context = sfContext::getInstance('frontend');
$context1 = sfContext::getInstance('i18n');
$context2 = sfContext::getInstance('cache');
$t->is(sfContext::getInstance('i18n'), $context1, '::getInstance() returns the named context if it already exists');
// ::switchTo();
$t->diag('::switchTo()');
sfContext::switchTo('i18n');
$t->is(sfContext::getInstance(), $context1, '::switchTo() changes the default context instance returned by ::getInstance()');
sfContext::switchTo('cache');
$t->is(sfContext::getInstance(), $context2, '::switchTo() changes the default context instance returned by ::getInstance()');
// ->get() ->set() ->has()
$t->diag('->get() ->set() ->has()');
$t->is($context1->has('object'), false, '->has() returns false if no object of the given name exist');
$object = new stdClass();
$context1->set('object', $object, '->set() stores an object in the current context instance');
$t->is($context1->has('object'), true, '->has() returns true if an object is stored for the given name');
$t->is($context1->get('object'), $object, '->get() returns the object associated with the given name');
try {
    $context1->get('object1');
    $t->fail('->get() throws an sfException if no object is stored for the given name');
} catch (sfException $e) {
    $t->pass('->get() throws an sfException if no object is stored for the given name');
}
$context['foo'] = $frontend_context;
开发者ID:Phennim,项目名称:symfony1,代码行数:31,代码来源:sfContextTest.php

示例7: removeNavCaches

 /**
  *
  */
 private function removeNavCaches()
 {
     $currentApp = sfContext::getInstance()->getConfiguration()->getApplication();
     $cacheApp = 'pc_frontend';
     if (!sfContext::hasInstance($cacheApp)) {
         sfContext::createInstance(ProjectConfiguration::getApplicationConfiguration($cacheApp, $this->getContext()->getConfiguration()->getEnvironment(), $this->getContext()->getConfiguration()->isDebug()));
     }
     sfContext::switchTo($cacheApp);
     if ($cache = sfContext::getInstance($cacheApp)->getViewCacheManager()) {
         $cache->remove('@sf_cache_partial?module=default&action=_globalNav&sf_cache_key=*');
         $cache->remove('@sf_cache_partial?module=default&action=_localNav&sf_cache_key=*');
     }
     sfContext::switchTo($currentApp);
 }
开发者ID:shotaatago,项目名称:OpenPNE3,代码行数:17,代码来源:actions.class.php

示例8: purgeCacheUri

 public function purgeCacheUri($cacheUri, $targetApplication = null, $hosts = '*')
 {
     $currentApplication = sfConfig::get('sf_app');
     if ($switchRequired = !is_null($targetApplication) && $targetApplication !== $currentApplication) {
         try {
             sfContext::switchTo($targetApplication);
         } catch (Exception $e) {
             $this->logError(sprintf('Impossible to invalidate template cache from "%s" application context "%s" (%s: %s)', $targetApplication, get_class($e), $e->getMessage()));
             return;
         }
         $viewCacheManager = sfContext::getInstance()->getViewCacheManager();
     } else {
         $viewCacheManager = $this->viewCacheManager;
     }
     if (!$viewCacheManager instanceof sfViewCacheManager) {
         return;
     }
     $error = null;
     try {
         $viewCacheManager->remove($cacheUri, $hosts);
     } catch (Exception $e) {
         if (sfConfig::get('sf_logging_enabled')) {
             $error = sprintf('Problem during cache invalidation process for uri "%s": %s', $cacheUri, $e->getMessage());
         }
     }
     if ($switchRequired) {
         sfContext::switchTo($currentApplication);
     }
     if (!is_null($error)) {
         $this->logError($error);
     }
 }
开发者ID:jeremyb,项目名称:akDoctrineTemplateCacheInvaliderPlugin,代码行数:32,代码来源:akTemplateCacheInvaliderListener.class.php

示例9: _app_url_for_internal_uri

function _app_url_for_internal_uri($application, $internal_uri, $absolute = false)
{
    // stores current states
    $current_application = sfContext::getInstance()->getConfiguration()->getApplication();
    $current_environment = sfContext::getInstance()->getConfiguration()->getEnvironment();
    $current_is_debug = sfContext::getInstance()->getConfiguration()->isDebug();
    $current_config = sfConfig::getAll();
    // computes a url
    if (sfContext::hasInstance($application)) {
        $context = sfContext::getInstance($application);
        sfContext::switchTo($application);
    } else {
        $config = ProjectConfiguration::getApplicationConfiguration($application, $current_environment, $current_is_debug);
        $context = sfContext::createInstance($config, $application);
    }
    $is_strip_script_name = (bool) sfConfig::get('sf_no_script_name');
    $result_url = $context->getController()->genUrl($internal_uri, $absolute);
    // restores the previous states
    sfContext::switchTo($current_application);
    sfConfig::add($current_config);
    // replaces a script name
    $before_script_name = basename(sfContext::getInstance()->getRequest()->getScriptName());
    $after_script_name = _create_script_name($application, $current_environment);
    if ($is_strip_script_name) {
        $before_script_name = '/' . $before_script_name;
        $after_script_name = '';
    }
    return str_replace($before_script_name, $after_script_name, $result_url);
}
开发者ID:phenom,项目名称:OpenPNE3,代码行数:29,代码来源:opUtilHelper.php

示例10: dirname

<?php

$app = 'frontend';
include dirname(__FILE__) . '/../bootstrap/functional.php';
new sfDatabaseManager($configuration);
$task = new sfDoctrineBuildTask($configuration->getEventDispatcher(), new sfFormatter());
$task->run(array(), array('sql', 'db', 'and-load', 'no-confirmation', 'application' => $app));
$conn = Doctrine::getConnectionByTableName('Article');
$conn->beginTransaction();
$browser = new sfTestFunctional(new sfBrowser());
$browser->get('/en/articles')->with('request')->begin()->isParameter('module', 'content')->isParameter('action', 'index')->isParameter('sf_culture', 'en')->end()->with('response')->begin()->checkElement('h1', '/Articles/')->checkElement('ul li', 2)->checkElement('ul li', '/My first article/')->checkElement('ul li', '/My second article/', array('position' => 1))->end()->with('view_cache')->begin()->isCached(true, false)->end()->click('My first article')->with('response')->begin()->checkElement('h1', '/My first article/')->checkElement('ul#comments li', 2)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$browser->test()->info('Updating first article with php code - cache invalidation is disabled on frontend');
$firstArticle = Doctrine::getTable('Article')->doSelectForSlug(array('slug' => 'my-first-article'));
$firstArticle->title = 'My first article, cache invalidation is disabled';
$firstArticle->save($conn);
$browser->get('/en/articles')->with('response')->begin()->checkElement('h1', '/Articles/')->checkElement('ul li', 2)->checkElement('ul li', '/My first article/')->checkElement('ul li:contains("cache invalidation is disabled")', false)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$browser->test()->info('Updating first article with php code - switch to backend');
sfContext::switchTo('backend');
$firstArticle = Doctrine::getTable('Article')->doSelectForSlug(array('slug' => 'my-first-article'));
$firstArticle->title = 'My first article, modified';
$firstArticle->save($conn);
sfContext::switchTo('frontend');
$browser->get('/en/articles')->with('response')->begin()->checkElement('h1', '/Articles/')->checkElement('ul li', 2)->checkElement('ul li', '/My first article, modified/')->checkElement('ul li', '/My second article/', array('position' => 1))->end()->with('view_cache')->begin()->isCached(true, false)->end()->click('My first article, modified')->with('response')->begin()->checkElement('h1', '/My first article, modified/')->checkElement('ul#comments li', 2)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$browser->test()->info('Updating first article from another app (with caching system disabled) - switch to backend');
sfContext::switchTo('backend');
$configuration->loadHelpers('Partial');
$backendBrowser = new sfTestFunctional(new sfBrowser());
$backendBrowser->get('/article/1/edit')->with('request')->begin()->isParameter('module', 'article')->isParameter('action', 'edit')->end()->setField('article[en][title]', 'My first article, edited')->click('Save')->followRedirect()->with('response')->begin()->checkElement('div.notice', 1)->end();
$browser->get('/en/article/' . $firstArticle->slug . '/view')->with('response')->begin()->checkElement('h1', '/My first article, edited/')->checkElement('ul#comments li', 2)->end()->with('view_cache')->begin()->isCached(true, false)->end();
$conn->rollback();
开发者ID:n1k0,项目名称:akDoctrineTemplateCacheInvaliderPlugin,代码行数:30,代码来源:InvaliderTest.php

示例11: setUp

 protected function setUp()
 {
     $app = $this->getApplication();
     if (!sfContext::hasInstance($app)) {
         $configuration = ProjectConfiguration::getApplicationConfiguration($app, $this->getEnvironment(), $this->isDebug());
         sfContext::createInstance($configuration, $app);
         require_once $configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
     }
     if ($app != sfContext::getInstance()->getConfiguration()->getApplication()) {
         sfContext::switchTo($app);
     }
     $this->testBrowser = new sfTestFunctional(new sfBrowser(), $this->getTest());
     $this->_start();
 }
开发者ID:wagnerpinheiro,项目名称:sf-php-unit2plugin,代码行数:14,代码来源:sf_phpunit_compiled.php

示例12: createContextInstance

 protected function createContextInstance($application, $enviroment)
 {
     $configuration = ProjectConfiguration::getApplicationConfiguration($application, $enviroment, 'false');
     sfContext::createInstance($configuration);
     sfContext::switchTo($application);
 }
开发者ID:nvidela,项目名称:kimkelen,代码行数:6,代码来源:csvColumnTransformTask.class.php

示例13: buildUrl

 /**
  * Génération brute de l'url cross app, passer par la fonction genUrl de préference (gestion du cache)
  *
  * @static
  * @throws Exception
  * @param string $app
  * @param string $url
  * @param bool $absolute
  * @param string $env
  * @param string $initialInstanceName for test purpose
  * @return mixed
  */
 public static function buildUrl($app, $url, $absolute = false, $env = null, $initialInstanceName = null)
 {
     $initialApp = sfConfig::get('sf_app');
     if ($initialInstanceName == null) {
         $initialInstanceName = $initialApp;
     }
     $initialScriptName = $_SERVER['SCRIPT_NAME'];
     $initialFrontController = basename($initialScriptName);
     $initialConfig = sfConfig::getAll();
     $debug = sfConfig::get('sf_debug');
     //environnement par défaut
     if ($env == null) {
         $env = $initialConfig['sf_environment'];
     }
     //création du contexte
     if (!sfContext::hasInstance($app)) {
         sfConfig::set('sf_factory_storage', 'sfNoStorage');
         // la config de base est restaurée à la fin de la fonction
         sfConfig::set('sf_use_database', false);
         $configuration = ProjectConfiguration::getApplicationConfiguration($app, $env, $debug);
         $context = sfContext::createInstance($configuration, $app);
         unset($configuration);
     } else {
         $context = sfContext::getInstance($app);
     }
     //détermination du front controller
     $finalFrontController = $app;
     if ($env != 'prod') {
         $finalFrontController .= '_' . $env;
     }
     $finalFrontController .= '.php';
     $crossUrl = $context->getController()->genUrl($url, $absolute);
     unset($context);
     //vérrification de l'existence du front controller
     if (!file_exists(sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . $finalFrontController)) {
         throw new Exception('Le front controller ' . $finalFrontController . ' est introuvable.');
     }
     $crossUrl = str_replace($initialFrontController, $finalFrontController, $crossUrl);
     //retour au context initial
     if ($app !== $initialInstanceName) {
         sfContext::switchTo($initialInstanceName);
         sfConfig::clear();
         sfConfig::add($initialConfig);
     }
     return $crossUrl;
 }
开发者ID:ratibus,项目名称:Crew,代码行数:58,代码来源:crossAppRouting.class.php

示例14: _initContext

 /** Initialize the application context.
  *
  * @return void
  */
 private function _initContext()
 {
     if (empty($this->_application)) {
         $this->_application = self::getDefaultApplicationName();
     }
     if (!sfContext::hasInstance()) {
         sfContext::createInstance($this->getApplicationConfiguration());
     }
     sfContext::switchTo($this->_application);
 }
开发者ID:todofixthis,项目名称:sfJwtPhpUnitPlugin,代码行数:14,代码来源:Case.class.php


注:本文中的sfContext::switchTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。