Checks to see if there has been a context created
public static hasInstance ( string $name = null ) : boolean | ||
$name | string | The name of the sfContext to check for |
리턴 | boolean | true is instanced, otherwise false |
/** * 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; } } }
/** * 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; }
/** * 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); } } }
/** * {@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; }
static function getUserId() { if (sfContext::hasInstance() && ($user = sfContext::getInstance()->getUser()->getGuardUser())) { return $user->id; } return sfGuardUserTable::SYSTEM_USER_ID; }
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; } }
protected function getDispatcher() { if (sfContext::hasInstance()) { return sfContext::getInstance()->getEventDispatcher(); } return null; }
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())))); }
public function getIsActive() { if (sfContext::hasInstance()) { return sfContext::getInstance()->getConfiguration()->isEnabledPlugin($this->name); } else { return $this->isActive; } }
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)); } }
protected static function notify($when, $action, $doctrineEvent) { if (!sfContext::hasInstance()) { return null; } $dispatcher = sfContext::getInstance()->getEventDispatcher(); $dispatcher->notify(new opDoctrineEvent($doctrineEvent, $when, $action)); }
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(); }
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]; } }
/** * 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; } }
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); }
/** * Initializes internationalization. */ public static function initializeI18n() { if (!self::$_initialized) { $dispatcher = sfProjectConfiguration::getActive()->getEventDispatcher(); $dispatcher->connect('user.change_culture', array('sfDoctrineRecord', 'listenToChangeCultureEvent')); if (sfContext::hasInstance() && ($user = sfContext::getInstance()->getUser())) { self::$_defaultCulture = $user->getCulture(); } self::$_initialized = true; } }
protected function setUp() { if (!sfContext::hasInstance('frontend')) { $configuration = new ProjectConfiguration(dirname(__FILE__) . '/../../fixtures/project'); sfContext::createInstance($configuration->getApplicationConfiguration('frontend', 'test', true)); } if (in_array('sfImageSource', stream_get_wrappers())) { stream_wrapper_unregister('sfImageSource'); } stream_wrapper_register('sfImageSource', 'sfImageSourceMock') or die('Failed to register protocol..'); }
/** * Initialize symfony propel * * @param sfEventDispatcher $dispatcher * @param string $culture * * @deprecated Moved to {@link sfPropelPluginConfiguration} */ public static function initialize(sfEventDispatcher $dispatcher, $culture = null) { $dispatcher->notify(new sfEvent(__CLASS__, 'application.log', array(__METHOD__ . '() has been deprecated. Please call sfPropel::setDefaultCulture() to set the culture.', 'priority' => sfLogger::NOTICE))); if (null !== $culture) { self::setDefaultCulture($culture); } else { if (class_exists('sfContext', false) && sfContext::hasInstance() && ($user = sfContext::getInstance()->getUser())) { self::setDefaultCulture($user->getCulture()); } } }
public function matchesUrl($url, $context = array()) { $result = parent::matchesUrl($url, $context); if (!$result) { return $result; } $message = array('This routing rule is deprecated. Please use other rules instead of this.', 'priority' => sfLogger::NOTICE); if (sfContext::hasInstance()) { sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', $message)); } return $result; }
public function postDelete(PropelPDO $con = null) { if (sfConfig::get('sf_environment') != "cli" or sfContext::hasInstance()) { $auditoria = new Auditorias(); //sfContext::getInstance()-getUser()-getAttribute('usuarioId') $auditoria->setAdministradoresId(sfContext::getInstance()->getUser()->getAttribute('usuarioId')); $auditoria->setObjeto('Pruebas'); $auditoria->setDescripcion(' Test : ' . $this->getTests()->getTitulo() . ' Evaluación : ' . $this->getEvaluaciones()->getNombre()); $auditoria->setTipooperacion('Eliminación de prueba'); $auditoria->save(); } }
public function postDelete(PropelPDO $con = null) { if (sfConfig::get('sf_environment') != "cli" or sfContext::hasInstance()) { $auditoria = new Auditorias(); //sfContext::getInstance()-getUser()-getAttribute('usuarioId') $auditoria->setAdministradoresId(sfContext::getInstance()->getUser()->getAttribute('usuarioId')); $auditoria->setObjeto('Aspirantes'); $auditoria->setDescripcion(' Cedula : ' . $this->getCedula() . ' Nombre : ' . $this->getNombre() . ' Apellido : ' . $this->getApellido()); $auditoria->setTipooperacion('Eliminación de aspirante'); $auditoria->save(); } }
protected function getCurrentWidgetKey($name) { $cookie = null; $request = sfContext::hasInstance('frontend') ? sfContext::getInstance()->getRequest() : null; if ($request != null) { $cookie = $request->getCookie($this->getCookieName($name)); } if ($cookie != null && array_key_exists($cookie, $this->widgets)) { return $cookie; } return $this->getOption('default_widget'); }
/** * Конструктор * * @param User $user * @param boolean $totalOnly Считать только главный тахометр */ public function __construct(User $user) { $this->user = $user; if (!sfContext::hasInstance()) { throw new sfException('Мы не знаем как парсить конфигурации'); } include sfContext::getInstance()->getConfigCache()->checkConfig('config/tahometers.yml'); // TODO: убить упоминания контекста $this->dispatcher = sfContext::getInstance()->getEventDispatcher(); $this->tahometersConfig = $tahometerConfig; $this->descriptionColors = $colors; }
public static function initialize(sfEventDispatcher $dispatcher, $culture = null) { $dispatcher->connect('user.change_culture', array('sfPropel', 'listenToChangeCultureEvent')); if (!is_null($culture)) { self::setDefaultCulture($culture); } else { if (class_exists('sfContext', false) && sfContext::hasInstance() && ($user = sfContext::getInstance()->getUser())) { self::setDefaultCulture($user->getCulture()); } } self::$initialized = true; }
public function postInsert(PropelPDO $con = null) { if (sfConfig::get('sf_environment') != "cli" or sfContext::hasInstance()) { $auditoria = new Auditorias(); //sfContext::getInstance()-getUser()-getAttribute('usuarioId') $auditoria->setAdministradoresId(sfContext::getInstance()->getUser()->getAttribute('usuarioId')); $auditoria->setObjeto('Asistencias'); $auditoria->setDescripcion('Aspirante : ' . $this->getAspirantes()->getCedula() . ' Evaluación : ' . $this->getEvaluaciones()->getNombre()); $auditoria->setTipooperacion('Alta de asistencia'); $auditoria->save(); } }
/** * 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); }
public function save(Doctrine_Connection $conn = null) { if (!$this->getOwnerId()) { if (sfContext::hasInstance()) { $user = sfContext::getInstance()->getUser(); if ($user->getGuardUser()) { $this->setOwnerId($user->getGuardUser()->getId()); } } } // Let the culture be the user's culture return aZendSearch::saveInDoctrineAndLucene($this, null, $conn); }
public function postInsert($values) { $log = new Log(); $log->setAction('Insert'); if (sfContext::hasInstance()) { $log->setUserId(sfContext::getInstance()->getUser()->getGuardUser()->getId()); } $log->setSiteId($this->Block->Section->Site->getId()); $log->setAsset($this->getId()); $log->setAssetTitle($this->getTitle()); $log->setClass('Display'); $log->save(); }
/** * Adds the new model */ public function insertIndex($node) { if (sfConfig::get('app_sfSolr_disable_listener', false)) { return; } if (sfContext::hasInstance()) { sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this, 'lucene.log', array('{sfLucene} deleting model "%s" with PK = "%s"', get_class($node), current($node->identifier())))); } foreach ($this->getSearchInstances($node) as $instance) { $instance->getIndexerFactory()->getModel($node)->insert(); $instance->getSearchService()->commit(); } }
protected function getContextByEmailAddress($address) { $application = 'pc_frontend'; if (opToolkit::isMobileEmailAddress($address)) { $application = 'mobile_frontend'; } if (!sfContext::hasInstance($application)) { $context = sfContext::createInstance($this->createConfiguration($application, 'prod'), $application); } else { $context = sfContext::getInstance($application); } return $context; }