getInstance() public static method

Retrieves the singleton instance of this class.
public static getInstance ( ) : sfCoreAutoload
return sfCoreAutoload A sfCoreAutoload implementation instance.
示例#1
0
 public function renderPdf($data, $pageSize = 'a4', $pageOrientation = 'portrait')
 {
     $previous_error_reporting = ini_get('error_reporting');
     // to avoid the complaining for fixing DOMPDF_FONT_DIR at
     // siwappConfiguration.class.php
     ini_set('error_reporting', E_ALL ^ E_NOTICE);
     $input_data = $this->render($data, true);
     sfCoreAutoload::getInstance()->unregister();
     sfAutoload::getInstance()->unregister();
     if (class_exists('sfAutoloadAgain')) {
         sfAutoloadAgain::getInstance()->unregister();
     }
     require_once sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'sfDomPDFPlugin' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'sfDomPDFPlugin.class.php';
     $q = new sfDomPDFPlugin($input_data);
     sfCoreAutoload::getInstance()->register();
     sfAutoload::getInstance()->register();
     if (class_exists('sfAutoloadAgain')) {
         sfAutoloadAgain::getInstance()->register();
     }
     $q->setProtocol('http://');
     $q->setHost($_SERVER['HTTP_HOST']);
     $q->setPaper($pageSize, $pageOrientation);
     $q->render();
     ini_set('error_reporting', $previous_error_reporting);
     return $q->getPdf();
 }
 /**
  * Reloads the autoloader.
  * 
  * @param  string $class
  * 
  * @return boolean
  */
 public function autoload($class)
 {
     // only reload once
     if ($this->reloaded) {
         return false;
     }
     $autoloads = spl_autoload_functions();
     // as of PHP 5.2.11, spl_autoload_functions() returns the object as the first element of the array instead of the class name
     if (version_compare(PHP_VERSION, '5.2.11', '>=')) {
         foreach ($autoloads as $position => $autoload) {
             if ($this === $autoload[0]) {
                 break;
             }
         }
     } else {
         $position = array_search(array(__CLASS__, 'autoload'), $autoloads, true);
     }
     if (isset($autoloads[$position + 1])) {
         $this->unregister();
         $this->register();
         // since we're rearranged things, call the chain again
         spl_autoload_call($class);
         return class_exists($class, false) || interface_exists($class, false);
     }
     $autoload = sfAutoload::getInstance();
     $autoload->reloadClasses(true);
     $this->reloaded = true;
     return $autoload->autoload($class);
 }
 /**
  * Various initializations.
  */
 public function initConfiguration()
 {
     $configCache = $this->getConfigCache();
     // in debug mode, start global timer
     if ($this->isDebug() && !sfWebDebugPanelTimer::isStarted()) {
         sfWebDebugPanelTimer::startTime();
     }
     // required core classes for the framework
     if (!$this->isDebug() && !sfConfig::get('sf_test') && !self::$coreLoaded) {
         $configCache->import('config/core_compile.yml', false);
     }
     // autoloader(s)
     $this->dispatcher->connect('autoload.filter_config', array($this, 'filterAutoloadConfig'));
     sfAutoload::getInstance()->register();
     if ($this->isDebug()) {
         sfAutoloadAgain::getInstance()->register();
     }
     // load base settings
     include $configCache->checkConfig('config/settings.yml');
     if ($file = $configCache->checkConfig('config/app.yml', true)) {
         include $file;
     }
     if (false !== sfConfig::get('sf_csrf_secret')) {
         sfForm::enableCSRFProtection(sfConfig::get('sf_csrf_secret'));
     }
     sfWidget::setCharset(sfConfig::get('sf_charset'));
     sfValidatorBase::setCharset(sfConfig::get('sf_charset'));
     // force setting default timezone if not set
     if ($default_timezone = sfConfig::get('sf_default_timezone')) {
         date_default_timezone_set($default_timezone);
     } else {
         if (sfConfig::get('sf_force_default_timezone', true)) {
             date_default_timezone_set(@date_default_timezone_get());
         }
     }
     // error settings
     ini_set('display_errors', $this->isDebug() ? 'on' : 'off');
     error_reporting(sfConfig::get('sf_error_reporting'));
     // initialize plugin configuration objects
     $this->initializePlugins();
     // compress output
     if (!self::$coreLoaded) {
         //      ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : '');
         ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : null);
     }
     self::$coreLoaded = true;
 }
 public function configure()
 {
     unset($this['moderated']);
     unset($this['post_id']);
     unset($this['moderated']);
     unset($this['created_at']);
     unset($this['updated_at']);
     if (!sfAutoload::getInstance()->loadClass('sfWidgetFormReCaptcha')) {
         throw new LogicException('Please install sfFormExtra : http://svn.symfony-project.com/plugins/sfFormExtraPlugin/');
     }
     $config = sfConfig::get('app_recaptcha_' . sfContext::getInstance()->getRequest()->getHost());
     $this->widgetSchema['captcha'] = new sfWidgetFormReCaptcha(array('public_key' => $config['public_key'], 'use_ssl' => true));
     $this->validatorSchema['captcha'] = new sfValidatorReCaptcha(array('private_key' => $config['private_key']));
     $this->validatorSchema['url'] = new sfValidatorUrl(array('required' => false));
     $this->validatorSchema['email'] = new sfValidatorEmail(array('required' => false));
     $this->validatorSchema['name'] = new swValidatorText(array('required' => true));
     $this->validatorSchema['message'] = new swValidatorText(array('required' => true));
 }
示例#5
0
<?php

/*
 * This file is part of the symfony package.
 * (c) 2004-2006 Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
$app = 'frontend';
if (!(include dirname(__FILE__) . '/../bootstrap/functional.php')) {
    return;
}
$b = new sfTestBrowser();
$b->get('/autoload/myAutoload')->with('request')->begin()->isParameter('module', 'autoload')->isParameter('action', 'myAutoload')->end()->with('response')->begin()->isStatusCode(200)->checkElement('body div', 'foo')->end();
$t = $b->test();
$autoload = sfAutoload::getInstance();
$t->ok(@file_get_contents($autoload->getClassPath('sfpropel'), FILE_USE_INCLUDE_PATH), '"sfAutoload" is case insensitive');
$t->ok(class_exists('BaseExtendMe'), 'plugin lib directory added to autoload');
$r = new ReflectionClass('ExtendMe');
$t->like(str_replace(DIRECTORY_SEPARATOR, '/', $r->getFilename()), '~fixtures/lib/ExtendMe~', 'plugin class can be replaced by project');
$t->ok(class_exists('NotInLib'), 'plugin autoload sets class paths');
$t->ok(!class_exists('ExcludedFromAutoload'), 'plugin autoload excludes directories');
示例#6
0
 /**
  * Initializes autoloaders.
  *
  * @param sfProjectConfiguration $configuration The current project or application configuration
  * @param boolean                $reload        If true, all autoloaders will be reloaded
  */
 protected function initializeAutoload(sfProjectConfiguration $configuration, $reload = false)
 {
     // sfAutoload
     if ($reload) {
         $this->logSection('autoload', 'Resetting application autoloaders');
         $finder = sfFinder::type('file')->name('*autoload.yml.php');
         $this->getFilesystem()->remove($finder->in(sfConfig::get('sf_cache_dir')));
         sfAutoload::getInstance()->reloadClasses(true);
     }
     // sfSimpleAutoload
     if (!$configuration instanceof sfApplicationConfiguration) {
         // plugins
         if ($reload) {
             foreach ($configuration->getPlugins() as $name) {
                 $configuration->getPluginConfiguration($name)->initializeAutoload();
             }
         }
         // project
         $autoload = sfSimpleAutoload::getInstance(sfConfig::get('sf_cache_dir') . '/project_autoload.cache');
         $autoload->loadConfiguration(sfFinder::type('file')->name('autoload.yml')->in(array(sfConfig::get('sf_symfony_lib_dir') . '/config/config', sfConfig::get('sf_config_dir'))));
         $autoload->register();
         if ($reload) {
             $this->logSection('autoload', 'Resetting CLI autoloader');
             $autoload->reload();
         }
     }
 }
 /**
  * @see sfProjectConfiguration
  */
 public function initConfiguration()
 {
     $configCache = $this->getConfigCache();
     // in debug mode, start global timer
     if ($this->isDebug() && !sfWebDebugPanelTimer::isStarted()) {
         sfWebDebugPanelTimer::startTime();
     }
     // required core classes for the framework
     if (!sfConfig::get('sf_debug') && !sfConfig::get('sf_test') && !self::$coreLoaded) {
         $configCache->import('config/core_compile.yml', false);
     }
     $this->dispatcher->connect('autoload.filter_config', array($this, 'filterAutoloadConfig'));
     sfAutoload::getInstance()->register();
     // load base settings
     include $configCache->checkConfig('config/settings.yml');
     if ($file = $configCache->checkConfig('config/app.yml', true)) {
         include $file;
     }
     if (false !== sfConfig::get('sf_csrf_secret')) {
         sfForm::enableCSRFProtection(sfConfig::get('sf_csrf_secret'));
     }
     sfWidget::setCharset(sfConfig::get('sf_charset'));
     sfValidatorBase::setCharset(sfConfig::get('sf_charset'));
     // force setting default timezone if not set
     if ($default_timezone = sfConfig::get('sf_default_timezone')) {
         date_default_timezone_set($default_timezone);
     } else {
         if (sfConfig::get('sf_force_default_timezone', true)) {
             date_default_timezone_set(@date_default_timezone_get());
         }
     }
     // error settings
     ini_set('display_errors', $this->isDebug() ? 'on' : 'off');
     error_reporting(sfConfig::get('sf_error_reporting'));
     // initialize plugin configuration objects
     $this->initializePlugins();
     // Disabled by default in symfony 1.1 because it causes problems with Doctrine.
     // If you want to enable it in your application, just copy the spl_autoload_register() line
     // in your configuration class.
     if (0 && $this->isDebug()) {
         spl_autoload_register(array(sfAutoload::getInstance(), 'autoloadAgain'));
     }
     // compress output
     if (!self::$coreLoaded) {
         if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4) {
             ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : '');
         }
     }
     self::$coreLoaded = true;
 }
 /**
  * @see sfProjectConfiguration
  */
 public function initConfiguration()
 {
     // in debug mode, start global timer
     if ($this->isDebug() && !sfConfig::get('sf_timer_start')) {
         sfConfig::set('sf_timer_start', microtime(true));
     }
     $configCache = $this->getConfigCache();
     // required core classes for the framework
     if (!sfConfig::get('sf_debug') && !sfConfig::get('sf_test') && !self::$coreLoaded) {
         $configCache->import('config/core_compile.yml', false);
         self::$coreLoaded = true;
     }
     sfAutoload::getInstance()->register();
     // load base settings
     include $configCache->checkConfig('config/settings.yml');
     if ($file = $configCache->checkConfig('config/app.yml', true)) {
         include $file;
     }
     if (false !== sfConfig::get('sf_csrf_secret')) {
         sfForm::enableCSRFProtection(sfConfig::get('sf_csrf_secret'));
     }
     // force setting default timezone if not set
     if ($default_timezone = sfConfig::get('sf_default_timezone')) {
         date_default_timezone_set($default_timezone);
     } else {
         if (sfConfig::get('sf_force_default_timezone', true)) {
             date_default_timezone_set(@date_default_timezone_get());
         }
     }
     // error settings
     ini_set('display_errors', $this->isDebug() ? 'on' : 'off');
     error_reporting(sfConfig::get('sf_error_reporting'));
     // include all config.php from plugins
     $this->loadPluginConfig();
     // Disabled by default in symfony 1.1 because it causes problems with Doctrine.
     // If you want to enable it in your application, just copy the spl_autoload_register() line
     // in your configuration class.
     if (0 && $this->isDebug()) {
         spl_autoload_register(array(sfAutoload::getInstance(), 'autoloadAgain'));
     }
     // compress output
     ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : '');
 }
 protected function standardBootstrap($app, $env = 'search')
 {
     $this->bootstrapSymfony($app, $env, true);
     sfAutoload::getInstance()->autoload('Propel');
     // see ticket #2613
 }