/**
   * Constructor.
   *
   * @param string            $environment    The environment name
   * @param Boolean           $debug          true to enable debug mode
   * @param string            $rootDir        The project root directory
   * @param sfEventDispatcher $dispatcher     An event dispatcher
   */
  public function __construct($environment, $debug, $rootDir = null, sfEventDispatcher $dispatcher = null)
  {
    $this->environment = $environment;
    $this->debug       = (boolean) $debug;
    $this->application = str_replace('Configuration', '', get_class($this));

    parent::__construct($rootDir, $dispatcher);

    $this->configure();

    $this->initConfiguration();

    if (sfConfig::get('sf_check_lock'))
    {
      $this->checkLock();
    }

    if (file_exists($file = sfConfig::get('sf_app_cache_dir').'/config/configuration.php'))
    {
      $this->cache = require $file;
    }

    $this->initialize();

    // store current sfConfig values
    $this->config = sfConfig::getAll();
  }
예제 #2
0
 /**
  * Returns the current application context.
  *
  * @param  bool $forceReload  true to force context reload, false otherwise
  *
  * @return sfContext
  */
 public function getContext($forceReload = false)
 {
     if (null === $this->context || $forceReload) {
         $isContextEmpty = null === $this->context;
         $context = $isContextEmpty ? sfContext::getInstance() : $this->context;
         // create configuration
         $currentConfiguration = $context->getConfiguration();
         $configuration = ProjectConfiguration::getApplicationConfiguration($currentConfiguration->getApplication(), $currentConfiguration->getEnvironment(), $currentConfiguration->isDebug());
         // connect listeners
         $configuration->getEventDispatcher()->connect('application.throw_exception', array($this, 'listenToException'));
         foreach ($this->listeners as $name => $listener) {
             $configuration->getEventDispatcher()->connect($name, $listener);
         }
         // create context
         $this->context = sfContext::createInstance($configuration);
         unset($currentConfiguration);
         if (!$isContextEmpty) {
             sfConfig::clear();
             sfConfig::add($this->rawConfiguration);
         } else {
             $this->rawConfiguration = sfConfig::getAll();
         }
     }
     return $this->context;
 }
 /**
  * Removes a key from symfony config
  */
 public function remove($key)
 {
     $all = sfConfig::getAll();
     unset($all[$key]);
     sfConfig::clear();
     sfConfig::add($all);
     return $this;
 }
 protected function execute($arguments = array(), $options = array())
 {
     parent::execute($arguments, $options);
     $this->mailLog('starting openpne:send-birthday-mail-lite task');
     // load templates
     list($pcTitleTpl, $pcTpl) = $this->getTwigTemplate('pc', 'birthday_lite');
     $birthday = $this->fetchRow('SELECT id, is_edit_public_flag, default_public_flag FROM ' . $this->getTableName('Profile') . ' WHERE name = ?', array('op_preset_birthday'));
     if (!$birthday) {
         throw new sfException('This project doesn\'t have the op_preset_birthday profile item.');
     }
     if (!$birthday['is_edit_public_flag'] && ProfileTable::PUBLIC_FLAG_PRIVATE == $birthday['default_public_flag']) {
         throw new sfException('all user\'s op_preset_birthday public_flag is hidden from backend');
     }
     $birthDatetime = new DateTime();
     $birthDatetime->modify('+ 1 week');
     $query = 'SELECT member_id FROM ' . $this->getTableName('MemberProfile') . ' WHERE profile_id = ? AND DATE_FORMAT(value_datetime, ?) = ?';
     $params = array($birthday['id'], '%m-%d', $birthDatetime->format('m-d'));
     if ($birthday['is_edit_public_flag']) {
         $query .= ' AND public_flag <> ?';
         $params[] = ProfileTable::PUBLIC_FLAG_PRIVATE;
     }
     if (null !== $options['start-member-id'] && is_numeric($options['start-member-id'])) {
         $query .= ' AND member_id >= ?';
         $params[] = $options['start-member-id'];
     }
     if (null !== $options['end-member-id'] && is_numeric($options['end-member-id'])) {
         $query .= ' AND member_id <= ?';
         $params[] = $options['end-member-id'];
     }
     $memberProfilesStmt = $this->executeQuery($query, $params);
     if ($memberProfilesStmt instanceof PDOStatement) {
         $sf_config = sfConfig::getAll();
         $op_config = new opConfig();
         while ($memberProfile = $memberProfilesStmt->fetch(Doctrine::FETCH_NUM)) {
             $birthMember = $this->getMember($memberProfile[0]);
             $birthMember['birthday'] = $birthDatetime->format('U');
             $ids = $this->getFriendIds($memberProfile[0]);
             foreach ($ids as $id) {
                 $member = $this->getMember($id);
                 $pcAddress = $this->getMemberPcEmailAddress($id);
                 if (!$pcAddress) {
                     continue;
                 }
                 $params = array('member' => $member, 'birthMember' => $birthMember, 'op_config' => $op_config, 'sf_config' => $sf_config);
                 $subject = $pcTitleTpl->render($params);
                 $body = $pcTpl->render($params);
                 try {
                     $this->sendMail($subject, $pcAddress, $this->adminMailAddress, $body);
                     $this->mailLog(sprintf("sent member %d birthday notification mail to member %d (usage memory:%s bytes)", $birthMember['id'], $member['id'], number_format(memory_get_usage())));
                 } catch (Zend_Mail_Transport_Exception $e) {
                     $this->mailLog(sprintf("%s (about member %d birthday to member %d)", $e->getMessage(), $birthMember['id'], $member['id']));
                 }
             }
         }
     }
     $this->mailLog('end openpne:send-birthday-mail-lite task');
 }
 /** Restores all sfConfig values to their state before the current test was
  *   run.
  *
  * @return static
  */
 public function flushConfigs()
 {
     if (isset(self::$_configs)) {
         sfConfig::clear();
         sfConfig::add(self::$_configs);
     } else {
         self::$_configs = sfConfig::getAll();
     }
     return $this;
 }
예제 #6
0
 /**
  * Clear conf for a given key
  */
 public static function clearAll()
 {
     foreach (sfConfig::getAll() as $key => $value) {
         if (preg_match('/^' . self::prefix() . '/', $key, $matches)) {
             if (isset($matches[0][1])) {
                 self::clear($matches[0][1]);
             }
         }
     }
 }
 public function execute($request)
 {
     // loop through application settings and extract enabled i18n languages
     foreach (sfConfig::getAll() as $setting => $value) {
         if (0 === strpos($setting, 'app_i18n_languages')) {
             $enabledI18nLanguages[$value] = format_language($value, $value);
         }
     }
     // sort languages by alpha code to look pretty
     ksort($enabledI18nLanguages);
     $this->enabledI18nLanguages = $enabledI18nLanguages;
 }
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     //    $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     $cfg = sfConfig::getAll();
     if (!isset($options['application'])) {
         echo ' NOTICE: set --application if you want the application config displayed.' . PHP_EOL;
     }
     if (!isset($options['env'])) {
         echo ' NOTICE: set --env if you want the application config displayed.' . PHP_EOL;
     }
     echo 'Configuration for env = ' . $options['env'] . ', application = ' . $options['application'] . PHP_EOL . PHP_EOL;
     print_r($cfg);
 }
 /**
  * Executes the filter chain.
  *
  * @param sfFilterChain $filterChain
  */
 public function execute($filterChain)
 {
     $config = sfConfig::getAll();
     $host = sfContext::getInstance()->getRequest()->getHost();
     foreach ($config as $key => $value) {
         if ($key == 'dm_' . $host) {
             foreach ($value as $subkey => $subval) {
                 $config['dm_' . $subkey] = $subval;
             }
         }
     }
     sfConfig::clear();
     sfConfig::add($config);
     $filterChain->execute();
 }
 /**
  * Executes index action
  *
  * @param      sfRequest $request A request object
  * @author     uechoco
  * @see        sfOpenPNEMailSend::getMailTemplate()
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->getResponse()->setTitle($this->freepage->getTitle());
     $context = sfContext::getInstance();
     $params['sf_config'] = sfConfig::getAll();
     // The renderer name is twig.
     // The template name ,which is the first argument of opFreepageTemplateLoaderDoctrine::doLoad(), is Freepage::id.
     $view = new sfTemplatingComponentPartialView($context, 'freepage', 'twig:' . $this->freepage->getId(), '');
     $context->set('view_instance', $view);
     $view->setPartialVars($params);
     $view->setAttribute('renderer_config', array('twig' => 'opTemplateRendererTwig'));
     $view->setAttribute('rule_config', array('twig' => array(array('loader' => 'opFreepageTemplateLoaderDoctrine', 'renderer' => 'twig', 'model' => 'Freepage'))));
     $view->execute();
     $this->body = $view->render();
 }
 /**
  * Parses the given configuration from the app.yml into an xCSS config array.
  *
  * @param bool $force If true, loads the configuration again, otherwise returns cached config, if any.
  *
  * @return array
  */
 public static function getXCSSConfiguration($force = false)
 {
     static $xCSSConfiguration = array();
     if ($force || empty($xCSSConfiguration)) {
         $configPrefix = 'app_xcssplugin_';
         foreach (sfConfig::getAll() as $entry => $value) {
             if (strstr($entry, $configPrefix) !== false) {
                 $xCSSConfiguration[str_replace($configPrefix, '', $entry)] = $value;
             }
         }
         // set default config items, if not set by user
         $xCSSConfiguration = array_merge(self::getDefaultXCSSConfiguration(), $xCSSConfiguration);
     }
     return $xCSSConfiguration;
 }
예제 #12
0
 /**
  * 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;
 }
 public function executeDailyNews()
 {
     $env = 'mobile_frontend' == sfConfig::get('sf_app') ? 'mobile' : 'pc';
     $twigEnvironment = new Twig_Environment(new Twig_Loader_String());
     $valueTpl = $twigEnvironment->loadTemplate(opDiaryPluginToolkit::getMailTemplate($env, 'diaryGagdet'));
     $diaries = Doctrine::getTable('Diary')->getFriendDiaryList($member['id'], 5);
     if (!count($diaries)) {
         return sfView::NONE;
     }
     $result = array();
     foreach ($diaries as $key => $diary) {
         $result[$key]['Member'] = $diary->Member;
         $result[$key]['title'] = $diary->title;
         $result[$key]['id'] = $diary->id;
     }
     $params = array('diaries' => $result, 'count' => count($diaries), 'sf_config' => sfConfig::getAll());
     $this->value = $valueTpl->render($params);
 }
 /**
  * Constructor.
  *
  * @param string            $environment    The environment name
  * @param Boolean           $debug          true to enable debug mode
  * @param string            $rootDir        The project root directory
  * @param sfEventDispatcher $dispatcher     An event dispatcher
  */
 public function __construct($environment, $debug, $rootDir = null, sfEventDispatcher $dispatcher = null)
 {
     $this->environment = $environment;
     $this->debug = (bool) $debug;
     $this->application = str_replace('Configuration', '', get_class($this));
     parent::__construct($rootDir, $dispatcher);
     $this->configure();
     $this->initConfiguration();
     if (sfConfig::get('sf_check_lock')) {
         $this->checkLock();
     }
     if (sfConfig::get('sf_check_symfony_version')) {
         $this->checkSymfonyVersion();
     }
     $this->initialize();
     // store current sfConfig values
     $this->config = sfConfig::getAll();
 }
예제 #15
0
 public static function getMailTemplate($template, $target = 'pc', $params = array(), $isOptional = true, $context = null)
 {
     if (!$context) {
         $context = sfContext::getInstance();
     }
     $params['sf_config'] = sfConfig::getAll();
     $view = new sfTemplatingComponentPartialView($context, 'superGlobal', 'notify_mail:' . $target . '_' . $template, '');
     $context->set('view_instance', $view);
     $view->setPartialVars($params);
     $view->setAttribute('renderer_config', array('twig' => 'opTemplateRendererTwig'));
     $view->setAttribute('rule_config', array('notify_mail' => array(array('loader' => 'sfTemplateSwitchableLoaderDoctrine', 'renderer' => 'twig', 'model' => 'NotificationMail'), array('loader' => 'opNotificationMailTemplateLoaderConfigSample', 'renderer' => 'twig'), array('loader' => 'opNotificationMailTemplateLoaderFilesystem', 'renderer' => 'php'))));
     $view->execute();
     try {
         return $view->render();
     } catch (InvalidArgumentException $e) {
         if ($isOptional) {
             return '';
         }
         throw $e;
     }
 }
예제 #16
0
 /**
  * Returns the current application context.
  *
  * @param  bool $forceReload  true to force context reload, false otherwise
  *
  * @return sfContext
  */
 public function getContext($forceReload = false)
 {
     if (is_null($this->context) || $forceReload) {
         if (!is_null($this->context)) {
             $currentConfiguration = $this->context->getConfiguration();
             $configuration = ProjectConfiguration::getApplicationConfiguration($currentConfiguration->getApplication(), $currentConfiguration->getEnvironment(), $currentConfiguration->isDebug());
             $this->context = sfContext::createInstance($configuration);
             unset($currentConfiguration);
             sfConfig::clear();
             sfConfig::add($this->rawConfiguration);
         } else {
             $this->context = sfContext::getInstance();
             $this->context->initialize($this->context->getConfiguration());
             $this->rawConfiguration = sfConfig::getAll();
         }
         $this->context->getEventDispatcher()->connect('application.throw_exception', array($this, 'ListenToException'));
         foreach ($this->listeners as $name => $listener) {
             $this->context->getEventDispatcher()->connect($name, $listener);
         }
     }
     return $this->context;
 }
 /**
  * Get list of currently enabled languages from config
  *
  * @return array enabled language codes and names
  */
 public static function getEnabledI18nLanguages()
 {
     //determine the currently enabled i18n languages
     $enabledI18nLanguages = array();
     foreach (sfConfig::getAll() as $setting => $value) {
         if (0 === strpos($setting, 'app_i18n_languages')) {
             $enabledI18nLanguages[substr($setting, 19)] = $value;
         }
     }
     return $enabledI18nLanguages;
 }
예제 #18
0
파일: sfConfigTest.php 프로젝트: hunde/bsc
// ::get() ::set()
$t->diag('::get() ::set()');
sfConfig::clear();
sfConfig::set('foo', 'bar');
$t->is(sfConfig::get('foo'), 'bar', '::get() returns the value of key config');
$t->is(sfConfig::get('foo1', 'default_value'), 'default_value', '::get() takes a default value as its second argument');
// ::has()
$t->diag('::has()');
sfConfig::clear();
$t->is(sfConfig::has('foo'), false, '::has() returns false if the key config does not exist');
sfConfig::set('foo', 'bar');
$t->is(sfConfig::has('foo'), true, '::has() returns true if the key config exists');
// ::add()
$t->diag('::add()');
sfConfig::clear();
sfConfig::set('foo', 'bar');
sfConfig::set('foo1', 'foo1');
sfConfig::add(array('foo' => 'foo', 'bar' => 'bar'));
$t->is(sfConfig::get('foo'), 'foo', '::add() adds an array of config parameters');
$t->is(sfConfig::get('bar'), 'bar', '::add() adds an array of config parameters');
$t->is(sfConfig::get('foo1'), 'foo1', '::add() adds an array of config parameters');
// ::getAll()
$t->diag('::getAll()');
sfConfig::clear();
sfConfig::set('foo', 'bar');
sfConfig::set('foo1', 'foo1');
$t->is(sfConfig::getAll(), array('foo' => 'bar', 'foo1' => 'foo1'), '::getAll() returns all config parameters');
// ::clear()
$t->diag('::clear()');
sfConfig::clear();
$t->is(sfConfig::get('foo1'), null, '::clear() removes all config parameters');
예제 #19
0
 public function executeConfigShow()
 {
   $this->setLayout(sfLoader::getTemplateDir('sfControlPanel', 'layout.php').'/layout');
   $config = sfConfig::getAll();
   ksort($config);
   $this->config = $config;
 }
예제 #20
0
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);
}
 protected function _backupSfConfig()
 {
     $this->_backupSfConfig = sfConfig::getAll();
 }
<a class="menu" href="#"><?php 
echo __('Language');
?>
</a>

<ul>
  <?php 
foreach (sfConfig::getAll() as $name => $value) {
    ?>
    <?php 
    if ('app_i18n_languages' == substr($name, 0, 18)) {
        ?>
      <li<?php 
        if ($sf_user->getCulture() == $value) {
            ?>
 class="active"<?php 
        }
        ?>
><?php 
        echo link_to(format_language($value, $value), array('sf_culture' => $value) + $sf_request->getParameterHolder()->getAll());
        ?>
</li>
    <?php 
    }
    ?>
  <?php 
}
?>
</ul>
예제 #23
0
 protected static function dump($config = null)
 {
     $dump = array();
     $config = sfConfig::getAll();
     foreach ($config as $key => $value) {
         if (substr($key, 0, 18) == 'dm_dmConfig_cache_') {
             if (is_string($value)) {
                 $dump[] = sprintf('\'%s\' => \'%s\'', $key, addslashes($value));
             } elseif (is_bool($value)) {
                 $dump[] = sprintf('\'%s\' => %s', $key, $value ? 'true' : 'false');
             } else {
                 $dump[] = sprintf('\'%s\' => %s', $key, $value);
             }
         }
     }
     $content = sprintf('<?php sfConfig::add(array(%s));', implode(", \n\r", $dump));
     if (!file_exists(dirname(self::getCacheFileName()))) {
         @mkdir(dirname(self::getCacheFileName()));
         @chmod(dirname(self::getCacheFileName()), 0777);
     }
     @file_put_contents(self::getCacheFileName(), $content, LOCK_EX);
     @chmod(self::getCacheFileName(), 0777);
 }
예제 #24
0
 /**
  * Returns sfConfig variables as a sorted array.
  *
  * @return array sfConfig variables
  */
 public static function settingsAsArray()
 {
     $config = sfConfig::getAll();
     ksort($config);
     return $config;
 }
 protected function execute($arguments = array(), $options = array())
 {
     parent::execute($arguments, $options);
     $this->mailLog('starting openpne:send-daily-news-lite task');
     $this->dailyNewsDays = opConfig::get('daily_news_day');
     $today = time();
     // load templates
     list($titleTpl, $tpl) = $this->getTwigTemplate('pc', 'dailyNews_lite');
     $query = 'SELECT id, name FROM ' . $this->getTableName('Member') . ' WHERE (is_active = 1 OR is_active IS NULL)';
     $params = array();
     if (null !== $options['start-member-id'] && is_numeric($options['start-member-id'])) {
         $query .= ' AND id >= ?';
         $params[] = $options['start-member-id'];
     }
     if (null !== $options['end-member-id'] && is_numeric($options['end-member-id'])) {
         $query .= ' AND id <= ?';
         $params[] = $options['end-member-id'];
     }
     $stmtMember = $this->executeQuery($query, $params);
     if ($stmtMember instanceof PDOStatement) {
         $sf_config = sfConfig::getAll();
         $op_config = new opConfig();
         $isDailyNewsDay = $this->isDailyNewsDay();
         while ($member = $stmtMember->fetch(Doctrine::FETCH_ASSOC)) {
             $config = $this->getDailyNewsConfig($member['id']);
             if (1 == $config && !$isDailyNewsDay) {
                 continue;
             }
             if (false !== $config && !$config) {
                 continue;
             }
             $address = $this->getMemberPcEmailAddress($member['id']);
             if (!$address) {
                 continue;
             }
             $params = array('member' => $member, 'subject' => $template['title'], 'diaries' => $this->getFriendDiaryList($member['id']), 'communityTopics' => $this->getCommunityTopicList($member['id']), 'unreadMessages' => $this->getUnreadMessageList($member['id']), 'today' => $today, 'op_config' => $op_config, 'sf_config' => $sf_config);
             $subject = $titleTpl->render($params);
             $body = $tpl->render($params);
             try {
                 $this->sendMail($subject, $address, $this->adminMailAddress, $body);
                 $this->mailLog(sprintf("sent daily news to member %d (usage memory:%s bytes)", $member['id'], number_format(memory_get_usage())));
             } catch (Zend_Mail_Transport_Exception $e) {
                 $this->mailLog(sprintf("%s (member %d)", $e->getMessage(), $member['id']), sfLogger::ERR);
             }
         }
     }
     $this->mailLog('end openpne:send-daily-news-lite task');
 }