本文整理汇总了PHP中sfSimpleAutoload类的典型用法代码示例。如果您正苦于以下问题:PHP sfSimpleAutoload类的具体用法?PHP sfSimpleAutoload怎么用?PHP sfSimpleAutoload使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了sfSimpleAutoload类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sfDoctrineGuardLoginHistoryPlugin_autoload_again
function sfDoctrineGuardLoginHistoryPlugin_autoload_again($class)
{
$autoload = sfSimpleAutoload::getInstance();
$autoload->addDirectory(dirname(__FILE__) . '/../fixtures/project/lib/');
$autoload->reload();
return $autoload->autoload($class);
}
示例2: execute
protected function execute($arguments = array(), $options = array())
{
$autoloader = sfSimpleAutoload::getInstance();
$autoloader->addDirectory(sfConfig::get('sf_plugins_dir') . '/sfPropelMigrationsLightPlugin/lib');
$configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'],
$options['env'], true);
$databaseManager = new sfDatabaseManager($configuration);
$migrator = new sfMigrator;
if (isset($arguments['schema-version']) && ctype_digit($arguments['schema-version'])) {
$max = $arguments['schema-version'];
} else {
$max = $migrator->getMaxVersion();
}
$migrations = $migrator->getMigrationsToRunUpTo($max);
foreach ($migrations as $migration) {
echo "Marking as Migrated: $migration\n";
$migrator->markMigration($migration);
}
}
开发者ID:nationalfield,项目名称:nfPropelMigrationsLightPlugin,代码行数:25,代码来源:sfPropelMarkAsMigratedTask.class.php
示例3: generate
/**
* Generates classes and templates in cache.
* Usable parameters are
* - decorated_class required Defines the class to be decorated
* - generated_class required The name of the generated decorator class
* - file_format optional format of the filename of the file, default %s.class.php
* - path optional location of the generated decorator to be saved, default \cache\decorator
*
* @param array The parameters
*
* @return string The data to put in configuration cache
*/
public function generate($params = array())
{
if (!isset($params['decorated_class'], $params['generated_class'])) {
throw new InvalidArgumentException('To generate a decorator the \'decorated_class\' and \'generated_class\' parameters are required');
}
$this->decoratedClass = $params['decorated_class'];
if (!class_exists($this->decoratedClass)) {
throw new RuntimeException('Cannot create decorator for non existing class \'' . $this->decoratedClass . '\'');
}
$this->generatedClass = $params['generated_class'];
if (class_exists($this->generatedClass)) {
throw new RuntimeException('Cannot redeclare decorator as the class already exists \'' . $this->generatedClass . '\'');
}
$path = isset($params['path']) ? $params['path'] : sfConfig::get('sf_cache_dir') . '/decorator';
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$fileFormat = isset($params['file_format']) ? $params['file_format'] : '%s.class.php';
file_put_contents($path . '/' . sprintf($fileFormat, $this->generatedClass), $this->evalTemplate('sfDecoratorTemplate.php'));
$conf = $this->getGeneratorManager()->getConfiguration();
if ($conf instanceof sfApplicationConfiguration && !$conf->isDebug()) {
//register the generated class in the autoloader
sfSimpleAutoload::getInstance()->setClassPath($this->generatedClass, $path . '/' . sprintf($fileFormat, $this->generatedClass));
}
return "require_once('" . $path . '/' . sprintf($fileFormat, $this->generatedClass) . "');";
}
示例4: getInstance
/**
* Retrieves the singleton instance of this class.
*
* @param string $cacheFile The file path to save the cache
*
* @return sfSimpleAutoload A sfSimpleAutoload implementation instance.
*/
public static function getInstance($cacheFile = null)
{
if (!isset(self::$instance)) {
self::$instance = new sfSimpleAutoload($cacheFile);
}
return self::$instance;
}
示例5: doRun
/**
* @see sfTask
*/
protected function doRun(sfCommandManager $commandManager, $options)
{
$this->process($commandManager, $options);
$this->checkProjectExists();
$application = $commandManager->getArgumentSet()->hasArgument('application') ? $commandManager->getArgumentValue('application') : null;
$env = $commandManager->getOptionSet()->hasOption('env') ? $commandManager->getOptionValue('env') : 'test';
if (!is_null($application)) {
$this->checkAppExists($application);
require_once sfConfig::get('sf_config_dir') . '/ProjectConfiguration.class.php';
$isDebug = $commandManager->getOptionSet()->hasOption('debug') ? $commandManager->getOptionValue('debug') : true;
$this->configuration = ProjectConfiguration::getApplicationConfiguration($application, $env, $isDebug, null, $this->dispatcher);
} else {
if (file_exists(sfConfig::get('sf_config_dir') . '/ProjectConfiguration.class.php')) {
require_once sfConfig::get('sf_config_dir') . '/ProjectConfiguration.class.php';
$this->configuration = new ProjectConfiguration(null, $this->dispatcher);
} else {
$this->configuration = new sfProjectConfiguration(getcwd(), $this->dispatcher);
}
}
$autoloader = sfSimpleAutoload::getInstance();
foreach ($this->configuration->getModelDirs() as $dir) {
$autoloader->addDirectory($dir);
}
if (!is_null($this->commandApplication) && !$this->commandApplication->withTrace()) {
sfConfig::set('sf_logging_enabled', false);
}
return $this->execute($commandManager->getArgumentValues(), $commandManager->getOptionValues());
}
示例6: autoload
/**
* Autoloads symfony
* Note: This is not compatible with ->bootstrap()
* Code adopted from command/sfSymfonyCommandApplication.class.php
*/
public function autoload()
{
if ($this->autoload) {
return;
}
$this->autoload = 'simple';
require_once $this->sf_lib_dir . '/util/sfCore.class.php';
require_once $this->sf_lib_dir . '/config/sfConfig.class.php';
require_once $this->sf_lib_dir . '/util/sfSimpleAutoload.class.php';
require_once $this->sf_lib_dir . '/util/sfToolkit.class.php';
require_once $this->sf_lib_dir . '/util/sfFinder.class.php';
sfConfig::add(array('sf_symfony_lib_dir' => $this->sf_lib_dir, 'sf_symfony_data_dir' => $this->sf_lib_dir));
// directory layout
sfCore::initDirectoryLayout($this->sf_lib_dir);
// include path
set_include_path(sfConfig::get('sf_lib_dir') . PATH_SEPARATOR . sfConfig::get('sf_app_lib_dir') . PATH_SEPARATOR . sfConfig::get('sf_model_dir') . PATH_SEPARATOR . get_include_path());
$cache = sfToolkit::getTmpDir() . DIRECTORY_SEPARATOR . sprintf('limeade_autoload_%s.data', md5(__FILE__));
$autoloader = sfSimpleAutoload::getInstance($cache);
$autoloader->register();
$finder = sfFinder::type('file')->ignore_version_control()->prune('test')->prune('vendor')->name('*.php');
$autoloader->addFiles($finder->in(sfConfig::get('sf_symfony_lib_dir')));
$autoloader->addFiles($finder->in($this->project_root));
$autoloader->addDirectory(sfConfig::get('sf_root_dir') . '/plugins');
return $this;
}
示例7: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
$this->schemaToXML(self::DO_NOT_CHECK_SCHEMA, 'generated-');
$this->copyXmlSchemaFromPlugins('generated-');
$this->callPhing('om', self::CHECK_SCHEMA);
$this->cleanup();
$this->logSection('autoload', 'reloading autoloading');
sfSimpleAutoload::getInstance()->reload();
}
示例8: initialize
public function initialize(sfEventDispatcher $dispatcher, sfFormatter $formatter)
{
parent::initialize($dispatcher, $formatter);
if (!self::$done) {
$libDir = dirname(__FILE__) . '/..';
$autoloader = sfSimpleAutoload::getInstance();
$autoloader->addDirectory($libDir);
$autoloader->register();
self::$done = true;
}
}
示例9: boot
public function boot($app = 'admin', $env = 'test', $debug = true)
{
$this->bootFast($app, $env, $debug);
// autoloader
$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();
$this->initialize();
dmDb::table('DmPage')->checkBasicPages();
return $this;
}
示例10: execute
protected function execute($arguments = array(), $options = array())
{
$databaseManager = new sfDatabaseManager($this->configuration);
$tmpdir = sfConfig::get('sf_cache_dir') . '/models_tmp';
$ymlTmp = $tmpdir . '/yaml';
$modelTmp = $tmpdir . '/model';
$this->getFileSystem()->mkdirs($ymlTmp);
$this->getFileSystem()->mkdirs($modelTmp);
$migrationsPath = sfConfig::get('sf_data_dir') . '/migrations/generated';
$config = $this->getCliConfig();
$manager = Doctrine_Manager::getInstance();
$oldAttr = $manager->getAttribute(Doctrine::ATTR_MODEL_LOADING);
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_AGGRESSIVE);
sfSimpleAutoload::unregister();
Doctrine::generateYamlFromDb($ymlTmp . '/from.yml', array(), array('generateBaseClasses' => false));
sfSimpleAutoload::register();
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, $oldAttr);
$models = sfFinder::type('file')->name('*.php')->in($config['models_path']);
foreach ($models as $model) {
$dirname = basename(dirname($model));
$filename = basename($model);
if ('base' !== $dirname) {
continue;
}
$normalModelName = str_replace('Base', '', basename($model, '.class.php'));
$normalModelRefClass = new ReflectionClass($normalModelName);
if ($normalModelRefClass && $normalModelRefClass->isAbstract()) {
continue;
}
$content = file_get_contents($model);
$content = str_replace('abstract class Base', 'class ToPrfx', $content);
$content = str_replace('extends opDoctrineRecord', 'extends Doctrine_Record', $content);
$matches = array();
if (preg_match('/\\$this->setTableName\\(\'([^\']+)\'\\);/', $content, $matches)) {
$tableName = $matches[1];
$content = preg_replace('/class [a-zA-Z0-9_]+/', 'class ToPrfx' . Doctrine_Inflector::classify($tableName), $content);
file_put_contents($modelTmp . '/ToPrfx' . Doctrine_Inflector::classify($tableName) . '.class.php', $content);
} else {
file_put_contents($modelTmp . '/' . str_replace('Base', 'ToPrfx', $filename), $content);
}
}
$migration = new Doctrine_Migration($migrationsPath);
$diff = new opMigrationDiff($ymlTmp . '/from.yml', $modelTmp, $migration);
$changes = $diff->generateMigrationClasses();
$this->getFileSystem()->remove($ymlTmp);
$this->getFileSystem()->remove($modelTmp);
$numChanges = count($changes, true) - count($changes);
if (!$numChanges) {
throw new Doctrine_Task_Exception('Could not generate migration classes from difference');
} else {
$this->dispatcher->notify(new sfEvent($this, 'command.log', array($this->formatter->formatSection('doctrine', 'Generated migration classes successfully from difference'))));
}
}
示例11: createConfiguration
protected function createConfiguration($application, $env)
{
$configuration = parent::createConfiguration($application, $env);
$autoloader = sfSimpleAutoload::getInstance();
$config = new sfAutoloadConfigHandler();
$mapping = $config->evaluate($configuration->getConfigPaths('config/autoload.yml'));
foreach ($mapping as $class => $file) {
$autoloader->setClassPath($class, $file);
}
$autoloader->register();
return $configuration;
}
示例12: execute
protected function execute($arguments = array(), $options = array())
{
$autoloader = sfSimpleAutoload::getInstance();
$autoloader->addDirectory(sfConfig::get('sf_plugins_dir') . '/sfPropelMigrationsLightPlugin/lib');
$migrator = new sfMigrator();
if (!is_dir($migrator->getMigrationsDir())) {
$this->getFilesystem()->mkDirs($migrator->getMigrationsDir());
}
$this->logSection('migrations', 'generating new migration stub');
$filename = $migrator->generateMigration($arguments['name']);
$this->logSection('file+', $filename);
}
示例13: execute
protected function execute($arguments = array(), $options = array())
{
$autoload = sfSimpleAutoload::getInstance();
$autoload->reload();
$autoload->saveCache();
$items = array();
if (file_exists(sfConfig::get('sf_upload_dir'))) {
$items[] = sfConfig::get('sf_upload_dir');
}
$items[] = sfConfig::get('sf_cache_dir');
$items[] = sfConfig::get('sf_web_dir') . '/cache';
$items[] = sfConfig::get('sf_config_dir');
$items[] = sfConfig::get('sf_data_dir');
$items[] = sfConfig::get('sf_log_dir');
$items[] = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . 'symfony';
// add the application
$apps = glob(sfConfig::get('sf_apps_dir') . '/*/config');
foreach ($apps as $app) {
$items[] = $app;
}
$appUsers = glob(sfConfig::get('sf_apps_dir') . '/*/lib/myUser.class.php');
foreach ($appUsers as $appUser) {
$items[] = $appUser;
}
$dirFinder = sfFinder::type('dir');
$fileFinder = sfFinder::type('file');
foreach ($items as $item) {
if ($this->isUnix()) {
try {
if (is_dir($item)) {
$this->getFilesystem()->execute('chmod -R 0777 ' . $item);
} else {
$this->getFilesystem()->execute('chmod 0777 ' . $item);
}
} catch (RuntimeException $e) {
$this->failed[] = $item;
}
} else {
@$this->getFilesystem()->chmod($item, 0777);
if (is_file($item)) {
continue;
}
@$this->getFilesystem()->chmod($dirFinder->in($items), 0777);
@$this->getFilesystem()->chmod($fileFinder->in($items), 0666);
}
}
// note those files that failed
if (count($this->failed)) {
$this->logBlock(array_merge(array('Permissions on the following file(s) or dir(s) could not be fixed:', ''), array_map(create_function('$f', 'return \' - \'.sfDebug::shortenFilePath($f);'), $this->failed)), 'ERROR_LARGE');
}
}
示例14: register
/**
* Register sfSimpleAutoload 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())));
}
if (self::getInstance()->cacheFile) {
register_shutdown_function(array(self::getInstance(), 'saveCache'));
}
self::$registered = true;
}
示例15: execute
protected function execute($arguments = array(), $options = array())
{
$autoloader = sfSimpleAutoload::getInstance();
$autoloader->addDirectory(sfConfig::get('sf_plugins_dir') . '/sfPropelMigrationsLightPlugin/lib');
$configuration = ProjectConfiguration::getApplicationConfiguration($arguments['application'], $options['env'], true);
$databaseManager = new sfDatabaseManager($configuration);
$migrator = new sfMigrator();
if (isset($arguments['schema-version']) && ctype_digit($arguments['schema-version'])) {
$runMigrationsCount = $migrator->migrate((int) $arguments['schema-version']);
} else {
$runMigrationsCount = $migrator->migrate();
}
$currentVersion = $migrator->getCurrentVersion();
$this->logSection('migrations', 'migrated ' . $runMigrationsCount . ' step(s)');
$this->logSection('migrations', 'current database version: ' . $currentVersion);
}