Created
April 2, 2010 11:26
-
-
Save kawahara/353040 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once dirname(__FILE__).'/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php'; | |
sfCoreAutoload::register(); | |
require_once dirname(__FILE__).'/../lib/util/sfPropelBaseTask.class.php'; | |
define('OPENPNE_CONFIGURAIOTN_SAMPLE_HASH', '7b73a69b5efd2d390bead8135e8a6335'); | |
if (!defined('E_DEPRECATED')) | |
{ | |
define('E_DEPRECATED', 8192); | |
} | |
class ProjectConfiguration extends sfProjectConfiguration | |
{ | |
// add | |
static protected $startTime; | |
static public function listenToPreCommandEvent(sfEvent $event) | |
{ | |
require_once dirname(__FILE__).'/../lib/behavior/opActivateBehavior.class.php'; | |
opActivateBehavior::disable(); | |
} | |
public function setup() | |
{ | |
$this->enableAllPluginsExcept(array('sfCompat10Plugin', 'sfPropelPlugin')); | |
$this->setIncludePath(); | |
$this->setOpenPNEConfiguration(); | |
sfConfig::set('sfDoctrinePlugin_doctrine_lib_path', sfConfig::get('sf_lib_dir').'/vendor/doctrine/Doctrine.php'); | |
sfConfig::set('doctrine_model_builder_options', array( | |
'baseClassName' => 'opDoctrineRecord', | |
)); | |
$this->dispatcher->connect('command.pre_command', array(__CLASS__, 'listenToPreCommandEvent')); | |
// add | |
if (sfConfig::get('sf_debug')) | |
{ | |
self::$startTime = microtime(true); | |
$this->dispatcher->connect('response.filter_content', array(__CLASS__, 'listenToRequestFilterContent')); | |
} | |
} | |
// add this method | |
static public function listenToRequestFilterContent(sfEvent $event, $content) | |
{ | |
$logfile = sfConfig::get('sf_log_dir').'/timer.log'; | |
if (sfTimerManager::getTimers()) | |
{ | |
$totalTime = null !== self::$startTime ? sprintf('%.0f', (microtime(true) - self::$startTime) * 1000) : 0; | |
$key = opToolkit::generatePasswordString(10, false); | |
$url = sfContext::getInstance()->getRequest()->getUri(); | |
$fp = fopen($logfile, 'a'); | |
foreach (sfTimerManager::getTimers() as $name => $timer) | |
{ | |
fwrite($fp, implode(',', array( | |
$key, | |
$url, | |
$name, | |
$timer->getCalls(), | |
$timer->getElapsedTime() * 1000, | |
$totalTime ? ($timer->getElapsedTime() * 1000 * 100 / $totalTime) : 'N/A') | |
)."\n"); | |
} | |
fclose($fp); | |
} | |
return $content; | |
} | |
protected function configureSessionStorage($name, $options = array()) | |
{ | |
$sessionName = 'OpenPNE_'.sfConfig::get('sf_app', 'default'); | |
$params = array('session_name' => $sessionName); | |
if ('memcache' === $name) | |
{ | |
sfConfig::set('sf_factory_storage', 'opMemcacheSessionStorage'); | |
sfConfig::set('sf_factory_storage_parameters', array_merge((array)$options, $params)); | |
} | |
elseif ('database' === $name) | |
{ | |
sfConfig::set('sf_factory_storage', 'opPDODatabaseSessionStorage'); | |
sfConfig::set('sf_factory_storage_parameters', array_merge(array( | |
'db_table' => 'session', | |
'database' => 'doctrine', | |
'db_id_col' => 'id', | |
'db_data_col' => 'data', | |
'db_time_col' => 'time', | |
), (array)$options, $params)); | |
} | |
elseif ('file' !== $name) | |
{ | |
sfConfig::set('sf_factory_storage', $name); | |
sfConfig::set('sf_factory_storage_parameters', array_merge((array)$options, $params)); | |
} | |
} | |
public function setIncludePath() | |
{ | |
sfToolkit::addIncludePath(array( | |
//PEAR | |
dirname(__FILE__).'/../lib/vendor/PEAR/', | |
dirname(__FILE__).'/../lib/vendor/OAuth/', | |
)); | |
} | |
public function configureDoctrine($manager) | |
{ | |
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true); | |
$manager->setAttribute(Doctrine::ATTR_RECURSIVE_MERGE_FIXTURES, true); | |
$manager->setAttribute(Doctrine::ATTR_QUERY_CLASS, 'opDoctrineQuery'); | |
// In default, OpenPNE uses foreign key. | |
// If you want not to use foreign key, comment out the following configuration: | |
// $manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL ^ Doctrine::EXPORT_CONSTRAINTS); | |
if (extension_loaded('apc')) | |
{ | |
$cacheDriver = new Doctrine_Cache_Apc(); | |
$manager->setAttribute(Doctrine::ATTR_QUERY_CACHE, $cacheDriver); | |
} | |
} | |
protected function setOpenPNEConfiguration() | |
{ | |
$path = dirname(__FILE__).'/OpenPNE.yml'; | |
if (md5_file($path.'.sample') !== OPENPNE_CONFIGURAIOTN_SAMPLE_HASH) | |
{ | |
die('You must use original '.dirname(__FILE__).DIRECTORY_SEPARATOR.'OpenPNE.yml.sample or you must use new '.dirname(__FILE__).DIRECTORY_SEPARATOR.'ProjectConfiguration.class.php'.PHP_EOL); | |
} | |
$config = sfYaml::load($path.'.sample'); | |
if (is_readable($path)) | |
{ | |
$config = array_merge($config, sfYaml::load($path)); | |
} | |
$this->configureSessionStorage($config['session_storage']['name'], (array)$config['session_storage']['options']); | |
unset($config['session_storage']); | |
foreach ($config as $key => $value) | |
{ | |
sfConfig::set('op_'.$key, $value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment