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


PHP sfContext::hasInstance方法代码示例

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


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

示例1: applyTCPDFConfig

 /**
  * Create all TCPDF specific constants.
  *
  * @author COil
  * @since  V1.6.0 - 7 apr 09
  *
  * @return Array
  */
 public static function applyTCPDFConfig($config)
 {
     foreach ($config as $key => $value) {
         switch ($key) {
             case 'K_TCPDF_EXTERNAL_CONFIG':
                 if ($value) {
                     define('K_TCPDF_EXTERNAL_CONFIG', true);
                 }
                 break;
             case 'K_PATH_MAIN':
                 if (empty($value)) {
                     $value = sfConfig::get('sfTCPDFPlugin_dir');
                 }
                 define('K_PATH_MAIN', $value);
                 break;
             case 'K_PATH_URL':
                 if (empty($value) && sfContext::hasInstance()) {
                     $value = sfContext::getInstance()->getRequest()->getUriPrefix() . '/';
                 }
                 define('K_PATH_URL', $value);
                 break;
             case 'K_PATH_FONTS':
                 if (empty($value)) {
                     $value = K_PATH_MAIN . 'fonts/';
                 }
                 define('K_PATH_FONTS', $value);
                 break;
             case 'K_PATH_CACHE':
                 if (empty($value)) {
                     $value = K_PATH_MAIN . 'cache/';
                 }
                 define('K_PATH_CACHE', $value);
                 break;
             case 'K_PATH_URL_CACHE':
                 if (empty($value)) {
                     $value = K_PATH_URL . 'cache/';
                 }
                 define('K_PATH_URL_CACHE', $value);
                 break;
             case 'K_PATH_IMAGES':
                 if (empty($value)) {
                     $value = K_PATH_MAIN . 'images/';
                 }
                 define('K_PATH_IMAGES', $value);
                 break;
             case 'K_BLANK_IMAGE':
                 if (empty($value)) {
                     $value = K_PATH_MAIN . 'images/';
                 }
                 define('K_BLANK_IMAGE', K_PATH_IMAGES . '_blank.png');
                 break;
             default:
                 // Only define a constant if it's a known TCPDF constant
                 if (in_array($key, self::getTCPDFConstantsList())) {
                     define($key, $value);
                 }
                 break;
         }
     }
 }
开发者ID:kcornejo,项目名称:estadistica,代码行数:68,代码来源:sfTCPDFPluginConfigHandler.class.php

示例2: set_datepicker_date_format

/**
 * Formats date using current date format.
 *
 * @param Date $date in YYYY-MM-DD format
 * @return formatted date.
 */
function set_datepicker_date_format($date)
{
    if (sfContext::hasInstance()) {
        $dateFormat = sfContext::getInstance()->getUser()->getDateFormat();
    } else {
        $configService = new ConfigService();
        $dateFormat = $configService->getAdminLocalizationDefaultDateFormat();
    }
    if (empty($date)) {
        $formattedDate = null;
    } else {
        $dateArray = explode('-', $date);
        $dateTime = new DateTime();
        $year = $dateArray[0];
        $month = $dateArray[1];
        $day = $dateArray[2];
        // For timestamp fields, clean time part from $day (day will look like "21 00:00:00"
        $day = trim($day);
        $spacePos = strpos($day, ' ');
        if ($spacePos !== FALSE) {
            $day = substr($day, 0, $spacePos);
        }
        $dateTime->setDate($year, $month, $day);
        $formattedDate = $dateTime->format($dateFormat);
    }
    return $formattedDate;
}
开发者ID:lahirwisada,项目名称:orangehrm,代码行数:33,代码来源:OrangeDateHelper.php

示例3: listenToRoutingLoadConfigurationEvent

 /**
  * Listens to the routing.load_configuration event.
  *
  * @param sfEvent An sfEvent instance
  */
 public static function listenToRoutingLoadConfigurationEvent(sfEvent $event)
 {
     $routing = $event->getSubject();
     $config = sfConfig::get('app_swToolbox_cross_link_application', array());
     if (!sfContext::hasInstance() || !$routing instanceof swPatternRouting) {
         return;
     }
     $configuration = sfContext::getInstance()->getConfiguration();
     $env = $configuration->getEnvironment();
     $app = $configuration->getApplication();
     if (!array_key_exists('enabled', $config[$app]) || !$config[$app]['enabled']) {
         return;
     }
     if (!array_key_exists('load', $config[$app]) || !is_array($config[$app]['load'])) {
         return;
     }
     foreach ($config[$app]['load'] as $app_to_load => $options) {
         $envs = $options['env'];
         $routes = isset($options['routes']) && is_array($options['routes']) ? $options['routes'] : array();
         if (!array_key_exists($env, $envs)) {
             continue;
         }
         $config_handler = new swCrossApplicationRoutingConfigHandler();
         $config_handler->setApp($app_to_load);
         $config_handler->setHost($envs[$env]);
         $config_handler->setRoutes($routes);
         $routes = $config_handler->evaluate(array(sfConfig::get('sf_apps_dir') . '/' . $app_to_load . '/config/routing.yml'));
         foreach ($routes as $name => $route) {
             $routing->appendRoute($name, $route);
         }
     }
 }
开发者ID:robinkanters,项目名称:dnsleergemeenschap,代码行数:37,代码来源:swToolboxCrossApplicationRouting.class.php

示例4: boot

 /**
  * {@inheritdoc}
  */
 public function boot(ContainerInterface $container)
 {
     if (empty($this->options)) {
         throw new \RuntimeException('You must provide options for the Symfony 1.4 kernel.');
     }
     if ($this->isBooted()) {
         return;
     }
     if ($this->classLoader && !$this->classLoader->isAutoloaded()) {
         $this->classLoader->autoload();
     }
     $dispatcher = $container->get('event_dispatcher');
     $event = new LegacyKernelBootEvent($container->get('request'), $this->options);
     $dispatcher->dispatch(LegacyKernelEvents::BOOT, $event);
     $this->options = $event->getOptions();
     require_once $this->rootDir . '/config/ProjectConfiguration.class.php';
     $application = $this->options['application'];
     $environment = $this->options['environment'];
     $debug = $this->options['debug'];
     $this->configuration = \ProjectConfiguration::getApplicationConfiguration($application, $environment, $debug, $this->getRootDir());
     $this->configuration->loadHelpers(array('Url'));
     // Create a context to use with some helpers like Url.
     if (!\sfContext::hasInstance()) {
         $session = $container->get('session');
         if ($session->isStarted()) {
             $session->save();
         }
         ob_start();
         \sfContext::createInstance($this->configuration);
         ob_end_flush();
         $session->migrate();
     }
     $this->isBooted = true;
 }
开发者ID:chancegarcia,项目名称:TheodoEvolutionLegacyWrapperBundle,代码行数:37,代码来源:Symfony14Kernel.php

示例5: getUserId

 static function getUserId()
 {
     if (sfContext::hasInstance() && ($user = sfContext::getInstance()->getUser()->getGuardUser())) {
         return $user->id;
     }
     return sfGuardUserTable::SYSTEM_USER_ID;
 }
开发者ID:silky,项目名称:littlesis,代码行数:7,代码来源:LsVersionableListener.class.php

示例6: onKernelResponse

    public function onKernelResponse(FilterResponseEvent $event)
    {
        if ($this->url || !$event->isMasterRequest() || !\sfContext::hasInstance()) {
            return;
        }
        $response_headers = $event->getResponse()->headers;
        if ($response_headers->has('x-debug-token-link') && strpos(\sfContext::getInstance()->getResponse()->getContentType(), 'javascript') === false && !$event->getRequest()->isXmlHttpRequest()) {
            $this->url = $response_headers->get('x-debug-token-link');
            $link = json_encode($response_headers->get('x-debug-token-link'));
            echo <<<JAVASCRIPT
<script>
(function() {
  var bar_node = document.getElementById('sfWebDebugDetails'), link_node, li_node;
  if(bar_node) { // We have a debug bar
    link_node = document.createElement('a');
    link_node.href = {$link};
    link_node.appendChild(document.createTextNode('Symfony 2'));
    li_node = document.createElement('li');
    li_node.appendChild(link_node);
    bar_node.insertBefore(li_node,bar_node.firstChild);
  }
}())
</script>
JAVASCRIPT;
        }
    }
开发者ID:eddypouw,项目名称:hnDependencyInjectionPlugin,代码行数:26,代码来源:DebugUrlTracker.php

示例7: getDispatcher

 protected function getDispatcher()
 {
     if (sfContext::hasInstance()) {
         return sfContext::getInstance()->getEventDispatcher();
     }
     return null;
 }
开发者ID:nvidela,项目名称:kimkelen,代码行数:7,代码来源:ncChangeLogUpdateChange.class.php

示例8: notify

 protected static function notify($when, $action, $doctrineEvent)
 {
     if (!sfContext::hasInstance()) {
         return null;
     }
     $dispatcher = sfContext::getInstance()->getEventDispatcher();
     $dispatcher->notify(new sfEvent(null, sprintf('op_doctrine.%s_%s_%s', $when, $action, get_class($doctrineEvent->getInvoker()))));
 }
开发者ID:kawahara,项目名称:OpenPNE3,代码行数:8,代码来源:opDoctrineEventNotifier.class.php

示例9: getIsActive

 public function getIsActive()
 {
     if (sfContext::hasInstance()) {
         return sfContext::getInstance()->getConfiguration()->isEnabledPlugin($this->name);
     } else {
         return $this->isActive;
     }
 }
开发者ID:kawahara,项目名称:OpenPNE3,代码行数:8,代码来源:opPlugin.class.php

示例10: setUp

 protected function setUp()
 {
     $this->projectConfiguration = new ProjectConfiguration(dirname(__FILE__) . '/../../fixtures/project/');
     $this->pluginConfiguration = new sfDoctrineGuardLoginHistoryPluginConfiguration($this->projectConfiguration);
     if (!sfContext::hasInstance('frontend')) {
         sfContext::createInstance($this->projectConfiguration->getApplicationConfiguration('frontend', 'test', true));
     }
 }
开发者ID:jmiridis,项目名称:atcsf1,代码行数:8,代码来源:sfDoctrineGuardLoginHistoryPluginConfigurationTest.php

示例11: notify

 protected static function notify($when, $action, $doctrineEvent)
 {
     if (!sfContext::hasInstance()) {
         return null;
     }
     $dispatcher = sfContext::getInstance()->getEventDispatcher();
     $dispatcher->notify(new opDoctrineEvent($doctrineEvent, $when, $action));
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:8,代码来源:opDoctrineEventNotifier.class.php

示例12: chooseConnection

 public static function chooseConnection($shouldGoToMaster = true, $queryType = self::SELECT)
 {
     if (!sfContext::hasInstance()) {
         return self::getMasterConnectionDirect();
     } elseif (0 == self::getMasterConnection()->transaction->getState() && (self::SELECT === $queryType && !$shouldGoToMaster)) {
         return self::getSlaveConnection();
     }
     return self::getMasterConnection();
 }
开发者ID:shotaatago,项目名称:OpenPNE3,代码行数:9,代码来源:opDoctrineQuery.class.php

示例13: __construct

 public function __construct($options = array(), $attributes = array())
 {
     parent::__construct($options, $attributes);
     $this->tinyMCEConfigs = array_merge($this->tinyMCEConfigs, $this->getOption('config'));
     if (!isset($this->tinyMCEConfigs['language']) && sfContext::hasInstance()) {
         $lang = explode('_', sfContext::getInstance()->getUser()->getCulture());
         $this->tinyMCEConfigs['language'] = $lang[0];
     }
 }
开发者ID:nise-nabe,项目名称:ppcon-sns,代码行数:9,代码来源:opWidgetFormRichTextarea.class.php

示例14: getContentRoutesYaml

    /**
     * Get the content routes yaml
     *
     * @return string $yaml
     */
    public static function getContentRoutesYaml()
    {
        $cachePath = sfConfig::get('sf_cache_dir') . '/' . sfConfig::get('sf_app') . '/' . sfConfig::get('sf_environment') . '/content_routes.cache.yml';
        if (file_exists($cachePath) && sfConfig::get('sf_environment') !== 'test') {
            return file_get_contents($cachePath);
        }
        try {
            $routeTemplate = '%s:
  url:   %s
  param:
    module: %s
    action: %s
    sf_format: html
    sympal_content_type: %s
    sympal_content_type_id: %s
    sympal_content_id: %s
  class: sfDoctrineRoute
  options:
    model: sfSympalContent
    type: object
    method: getContent
    allow_empty: true
  requirements:
    sf_culture:  (%s)
    sf_format:   (%s)
    sf_method:   [post, get]
';
            $routes = array();
            $siteSlug = sfConfig::get('sf_app');
            if (!sfContext::hasInstance()) {
                $configuration = ProjectConfiguration::getApplicationConfiguration(sfConfig::get('sf_app'), 'prod', false);
                sfContext::createInstance($configuration);
            }
            /*
             * Step 1) Process all sfSympalContent records with a custom_path,
             *         module, or action. These have sympal_content_* routes
             */
            $contents = Doctrine::getTable('sfSympalContent')->createQuery('c')->leftJoin('c.Type t')->innerJoin('c.Site s')->where("(c.custom_path IS NOT NULL AND c.custom_path != '') OR (c.module IS NOT NULL AND c.module != '') OR (c.action IS NOT NULL AND c.action != '')")->andWhere('s.slug = ?', $siteSlug)->execute();
            foreach ($contents as $content) {
                $routes['content_' . $content->getId()] = sprintf($routeTemplate, substr($content->getRouteName(), 1), $content->getRoutePath(), $content->getModuleToRenderWith(), $content->getActionToRenderWith(), $content->Type->name, $content->Type->id, $content->id, implode('|', sfSympalConfig::getLanguageCodes()), implode('|', sfSympalConfig::get('content_formats')));
            }
            /*
             * Step 2) Create a route for each sfSympalContentType record
             */
            $contentTypes = Doctrine::getTable('sfSympalContentType')->createQuery('t')->execute();
            foreach ($contentTypes as $contentType) {
                $routes['content_type_' . $contentType->getId()] = sprintf($routeTemplate, substr($contentType->getRouteName(), 1), $contentType->getRoutePath(), $contentType->getModuleToRenderWith(), $contentType->getActionToRenderWith(), $contentType->name, $contentType->id, null, implode('|', sfSympalConfig::getLanguageCodes()), implode('|', sfSympalConfig::get('content_formats')));
            }
            $routes = implode("\n", $routes);
            file_put_contents($cachePath, $routes);
            return $routes;
        } catch (Exception $e) {
            // for now, I'd like to not obfuscate the errors - rather reportthem
            throw $e;
        }
    }
开发者ID:sympal,项目名称:sympal,代码行数:61,代码来源:sfSympalContentToolkit.class.php

示例15: postDelete

 public function postDelete(Doctrine_Event $event)
 {
     //if called from task do nothing
     if (!sfContext::hasInstance()) {
         return;
     }
     //delete from index
     $searchIndex = new zsSearchIndex($this->_options['index']);
     $searchIndex->updateIndex($event->getInvoker(), true);
 }
开发者ID:kbond,项目名称:zsUtilPlugin,代码行数:10,代码来源:zsSearchableListener.class.php


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