This class is a singleton as PHP seems to be unable to register 2 autoloaders that are instances of the same class (why?).
Author: Fabien Potencier (fabien.potencier@symfony-project.com)
示例#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();
 }
 /**
  * Retrieves the singleton instance of this class.
  *
  * @return sfCoreAutoload A sfCoreAutoload implementation instance.
  */
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new sfCoreAutoload();
     }
     return self::$instance;
 }
示例#3
0
 /**
  * Register sfCoreAutoload in spl autoloader.
  *
  * @return void
  */
 public static function register()
 {
     if (self::$registered) {
         return;
     }
     ini_set('unserialize_callback_func', 'spl_autoload_call');
     if (false === spl_autoload_register(array(self::getInstance(), 'autoload'))) {
         throw new sfException(sprintf('Unable to register %s::autoload as an autoloading method.', get_class(self::getInstance())));
     }
     self::$registered = true;
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     require_once dirname(__FILE__) . '/../../vendor/lime/lime.php';
     require_once dirname(__FILE__) . '/lime_symfony.php';
     // cleanup
     require_once dirname(__FILE__) . '/../../util/sfToolkit.class.php';
     if ($files = glob(sys_get_temp_dir() . DIRECTORY_SEPARATOR . '/sf_autoload_unit_*')) {
         foreach ($files as $file) {
             unlink($file);
         }
     }
     // update sfCoreAutoload
     if ($options['update-autoloader']) {
         require_once dirname(__FILE__) . '/../../autoload/sfCoreAutoload.class.php';
         sfCoreAutoload::make();
     }
     $status = false;
     $statusFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . sprintf('/.test_symfony_%s_status', md5(dirname(__FILE__)));
     if ($options['only-failed']) {
         if (file_exists($statusFile)) {
             $status = unserialize(file_get_contents($statusFile));
         }
     }
     $h = new lime_symfony(array('force_colors' => $options['color'], 'verbose' => $options['trace']));
     $h->base_dir = realpath(dirname(__FILE__) . '/../../../test');
     // remove generated files
     if ($options['rebuild-all']) {
         $finder = sfFinder::type('dir')->name(array('base', 'om', 'map'));
         foreach ($finder->in(glob($h->base_dir . '/../lib/plugins/*/test/functional/fixtures/lib')) as $dir) {
             sfToolkit::clearDirectory($dir);
         }
     }
     if ($status) {
         foreach ($status as $file) {
             $h->register($file);
         }
     } else {
         $h->register(sfFinder::type('file')->prune('fixtures')->name('*Test.php')->in(array_merge(array($h->base_dir . '/unit'), glob($h->base_dir . '/../lib/plugins/*/test/unit'), array($h->base_dir . '/functional'), glob($h->base_dir . '/../lib/plugins/*/test/functional'), array($h->base_dir . '/other'))));
     }
     $ret = $h->run() ? 0 : 1;
     file_put_contents($statusFile, serialize($h->get_failed_files()));
     if ($options['xml']) {
         file_put_contents($options['xml'], $h->to_xml());
     }
     return $ret;
 }
 /**
  * Constructor.
  *
  * @param string              $rootDir    The project root directory
  * @param sfEventDispatcher   $dispatcher The event dispatcher
  */
 public function __construct($rootDir = null, sfEventDispatcher $dispatcher = null)
 {
     if (is_null(sfProjectConfiguration::$active) || $this instanceof sfApplicationConfiguration) {
         sfProjectConfiguration::$active = $this;
     }
     $this->rootDir = is_null($rootDir) ? self::guessRootDir() : realpath($rootDir);
     $this->symfonyLibDir = realpath(dirname(__FILE__) . '/..');
     // initializes autoloading for symfony core classes
     require_once $this->symfonyLibDir . '/autoload/sfCoreAutoload.class.php';
     sfCoreAutoload::register();
     $this->dispatcher = is_null($dispatcher) ? new sfEventDispatcher() : $dispatcher;
     ini_set('magic_quotes_runtime', 'off');
     ini_set('register_globals', 'off');
     sfConfig::set('sf_symfony_lib_dir', $this->symfonyLibDir);
     $this->setRootDir($this->rootDir);
     $this->setup();
 }
 public function bootstrap($app = 'frontend', $debug = true)
 {
     // so that all notices will appear
     error_reporting(E_ALL);
     // Load symfony core and lime testing framework
     require_once $this->getSymfonyDir() . '/autoload/sfCoreAutoload.class.php';
     sfCoreAutoload::register();
     // Create configuration and context
     require_once dirname(__FILE__) . '/../fixtures/project/config/ProjectConfiguration.class.php';
     $this->configuration = ProjectConfiguration::getApplicationConfiguration($app, 'test', $debug);
     require_once $this->configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
     $this->context = sfContext::createInstance($this->configuration);
     new sfDatabaseManager($this->configuration);
     // Register teardown / autoload functions
     spl_autoload_register(array($this, 'autoload'));
     register_shutdown_function(array($this, 'teardown'));
     // Cleanup and copy over SQLite DB
     $this->teardown();
     $this->setup();
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     if (file_exists('symfony')) {
         throw new sfCommandException(sprintf('A project named "%s" already exists in this directory.', $arguments['name']));
     }
     // create basic project structure
     $finder = sfFinder::type('any')->discard('.sf');
     $this->getFilesystem()->mirror(dirname(__FILE__) . '/skeleton/project', sfConfig::get('sf_root_dir'), $finder);
     // update project name and directory
     $finder = sfFinder::type('file')->name('properties.ini', 'apache.conf', 'propel.ini', 'databases.yml');
     $this->getFileSystem()->replaceTokens($finder->in(sfConfig::get('sf_config_dir')), '##', '##', array('PROJECT_NAME' => $arguments['name'], 'PROJECT_DIR' => sfConfig::get('sf_root_dir')));
     // update ProjectConfiguration class
     $this->getFileSystem()->replaceTokens(sfConfig::get('sf_config_dir') . '/ProjectConfiguration.class.php', '##', '##', array('SYMFONY_LIB_DIR' => sfConfig::get('sf_symfony_lib_dir')));
     // update vhost sample file
     $this->getFileSystem()->replaceTokens(sfConfig::get('sf_config_dir') . '/vhost.sample', '##', '##', array('PROJECT_NAME' => $arguments['name'], 'SYMFONY_WEB_DIR' => sfConfig::get('sf_web_dir'), 'SYMFONY_SF_DIR' => realpath(sfCoreAutoload::getInstance()->getBaseDir() . '../data/web/sf')));
     // fix permission for common directories
     $fixPerms = new sfProjectPermissionsTask($this->dispatcher, $this->formatter);
     $fixPerms->setCommandApplication($this->commandApplication);
     $fixPerms->run();
     // publish assets for core plugins
     $publishAssets = new sfPluginPublishAssetsTask($this->dispatcher, $this->formatter);
     $publishAssets->setCommandApplication($this->commandApplication);
     $publishAssets->run(array(), array('--core-only'));
 }
示例#8
0
<?php

require_once dirname(__FILE__) . '/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::register();
class ProjectConfiguration extends sfProjectConfiguration
{
    public function setup()
    {
        $this->enablePlugins('sfDoctrinePlugin');
        $this->enablePlugins('sfTCPDFPlugin');
        $this->enablePlugins('sfDoctrineGuardPlugin');
    }
}
 /**
  * Unregister sfCoreAutoload from spl autoloader.
  *
  * @return void
  */
 public static function unregister()
 {
     spl_autoload_unregister(array(self::getInstance(), 'autoload'));
     self::$registered = false;
 }
示例#10
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please component the LICENSE
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../bootstrap/unit.php';
$t = new lime_test(1);
$autoload = sfCoreAutoload::getInstance();
$t->is($autoload->getClassPath('sfaction'), $autoload->getBaseDir() . '/action/sfAction.class.php', '"sfCoreAutoload" is case-insensitive');
示例#11
0
文件: prove.php 项目: mediasadc/alba
<?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.
 */
require_once dirname(__FILE__) . '/../../lib/vendor/lime/lime.php';
class lime_symfony extends lime_harness
{
    protected function get_relative_file($file)
    {
        $file = str_replace(DIRECTORY_SEPARATOR, '/', str_replace(array(realpath($this->base_dir) . DIRECTORY_SEPARATOR, realpath($this->base_dir . '/../lib/plugins') . DIRECTORY_SEPARATOR, $this->extension), '', $file));
        return preg_replace('#^(.*?)Plugin/test/(unit|functional)/#', '[$1] $2/', $file);
    }
}
require_once dirname(__FILE__) . '/../../lib/util/sfToolkit.class.php';
if ($files = glob(sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . '/sf_autoload_unit_*')) {
    foreach ($files as $file) {
        unlink($file);
    }
}
// update sfCoreAutoload
require_once dirname(__FILE__) . '/../../lib/autoload/sfCoreAutoload.class.php';
sfCoreAutoload::make();
$h = new lime_symfony(new lime_output_color());
$h->base_dir = realpath(dirname(__FILE__) . '/..');
$h->register(sfFinder::type('file')->prune('fixtures')->name('*Test.php')->in(array_merge(array($h->base_dir . '/unit'), glob($h->base_dir . '/../lib/plugins/*/test/unit'), array($h->base_dir . '/functional'), glob($h->base_dir . '/../lib/plugins/*/test/functional'), array($h->base_dir . '/other'))));
exit($h->run() ? 0 : 1);
 public function bootstrap($app = 'frontend', $debug = true)
 {
     // so that all notices will appear
     error_reporting(E_ALL);
     // Load symfony core and lime testing framework
     require_once $this->getSymfonyDir() . '/autoload/sfCoreAutoload.class.php';
     sfCoreAutoload::register();
     // Create configuration and context
     require_once dirname(__FILE__) . '/../fixtures/project/config/ProjectConfiguration.class.php';
     $dbms = 'sqlite';
     if (isset($_SERVER['DB'])) {
         $dbms = strtolower($_SERVER['DB']);
     }
     // Check if configuration for dbms exists
     if (!file_exists(dirname(__FILE__) . '/../fixtures/project/config/database-' . $dbms . '.yml')) {
         throw new Exception('Didnt find database-' . $dbms . 'yml for DBMS: "' . $dbms . '"');
     }
     copy(dirname(__FILE__) . '/../fixtures/project/config/database-' . $dbms . '.yml', dirname(__FILE__) . '/../fixtures/project/config/databases.yml');
     $this->configuration = ProjectConfiguration::getApplicationConfiguration($app, 'test', $debug);
     require_once $this->configuration->getSymfonyLibDir() . '/vendor/lime/lime.php';
     $this->context = sfContext::createInstance($this->configuration);
     $this->databasemanager = new sfDatabaseManager($this->configuration);
     // Register teardown / autoload functions
     spl_autoload_register(array($this, 'autoload'));
     register_shutdown_function(array($this, 'teardown'));
     $this->teardown();
     $this->setup();
 }
<?php

require_once sfCoreAutoload::register();
class ProjectConfiguration extends sfProjectConfiguration
{
    public function setup()
    {
    }
}
示例#14
0
文件: symfony.php 项目: theolymp/diem
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
chdir(dirname(__FILE__));
require_once dirname(__FILE__) . '/config/ProjectConfiguration.class.php';
include sfCoreAutoload::getInstance()->getBaseDir() . '/command/cli.php';