/** * 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; }
public function init() { $hasMaxRecordLimit = $this->getMaxRecordLimit() !== false; $maxRecordLimit = $this->getMaxRecordLimit(); if (!$this->results) { $cForCount = clone $this->getCriteria(); $cForCount->setOffset(0); $cForCount->setLimit(0); $cForCount->clearGroupByColumns(); } // require the model class (because autoloading can crash under some conditions) if (!($classPath = sfCore::getClassPath($this->getClassPeer()))) { throw new sfException(sprintf('Unable to find path for class "%s".', $this->getClassPeer())); } require_once $classPath; $count = count($this->getResults(true)); $this->setNbResults($hasMaxRecordLimit ? min($count, $maxRecordLimit) : $count); if (!$this->results) { $c = $this->getCriteria(); $c->setOffset(0); $c->setLimit(0); } else { $this->offset = 0; $this->limit = 0; } if ($this->getPage() == 0 || $this->getMaxPerPage() == 0) { $this->setLastPage(0); } else { $this->setLastPage(ceil($this->getNbResults() / $this->getMaxPerPage())); $offset = ($this->getPage() - 1) * $this->getMaxPerPage(); $this->offset = $offset; if ($c) { $c->setOffset($this->offset); } if ($hasMaxRecordLimit) { $maxRecordLimit = $maxRecordLimit - $offset; if ($maxRecordLimit > $this->getMaxPerPage()) { if ($c) { $c->setLimit($this->getMaxPerPage()); } $this->limit = $this->getMaxPerPage(); } else { if ($c) { $c->setLimit($maxRecordLimit); } $this->limit = $maxRecordLimit; } } else { if ($c) { $c->setLimit($this->getMaxPerPage()); } $this->limit = $this->getMaxPerPage(); } } }
public static function retrieveObjects($class, $peerMethod = null) { if (!($classPath = sfCore::getClassPath($class . 'Peer'))) { throw new sfException(sprintf('Unable to find path for class "%s".', $class . 'Peer')); } require_once $classPath; if (!$peerMethod) { $peerMethod = 'doSelect'; } $classPeer = $class . 'Peer'; if (!is_callable(array($classPeer, $peerMethod))) { throw new sfException(sprintf('Peer method "%s" not found for class "%s"', $peerMethod, $classPeer)); } $objects = call_user_func(array($classPeer, $peerMethod), new Criteria()); return $objects; }
* (c) 2007 Rob Rosenbaum <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /* * The contents of this file came mostly from the following page: * http://www.symfony-project.com/snippets/snippet/215 */ if (!@constant('SF_APP')) { die('Constant "SF_APP" must be defined in your test script.' . "\n"); } if (!@constant('SF_ENVIRONMENT')) { // Only load constants in not done before (group tests) define('SF_ENVIRONMENT', 'test'); define('SF_DEBUG', TRUE); define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/../../..')); $_test_dir = SF_ROOT_DIR . '/test'; // symfony directories include SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; require_once $sf_symfony_lib_dir . '/vendor/lime/lime.php'; require_once $sf_symfony_lib_dir . '/util/sfCore.class.php'; require_once dirname(__FILE__) . '/../lib/sfPropelTest.php'; sfCore::initSimpleAutoload(array(SF_ROOT_DIR . '/lib/model', $sf_symfony_lib_dir, SF_ROOT_DIR . '/lib', SF_ROOT_DIR . '/apps/theApp/lib', SF_ROOT_DIR . '/plugins')); // Location plugins set_include_path($sf_symfony_lib_dir . '/vendor' . PATH_SEPARATOR . SF_ROOT_DIR . PATH_SEPARATOR . get_include_path()); sfCore::bootstrap($sf_symfony_lib_dir, $sf_symfony_data_dir); sfContext::getInstance(); Propel::setConfiguration(sfPropelDatabase::getConfiguration()); Propel::initialize(); }
public function getView($moduleName, $actionName, $viewName) { $file = sfConfig::get('sf_app_module_dir') . '/' . $moduleName . '/' . sfConfig::get('sf_app_module_view_dir_name') . '/' . $actionName . $viewName . 'View.class.php'; if (is_readable($file)) { require_once $file; $class = $actionName . $viewName . 'View'; $moduleClass = $moduleName . '_' . $class; if (class_exists($moduleClass, false)) { $class = $moduleClass; } } else { $viewName = $this->getContext()->getRequest()->getAttribute($moduleName . '_' . $actionName . '_view_name', sfConfig::get('mod_' . strtolower($moduleName) . '_view_class'), 'symfony/action/view'); $class = sfCore::getClassPath($viewName . 'View') ? $viewName . 'View' : 'sfPHPView'; } return new $class(); }
/** * Hook function to the Base Class function Save (post) * * @param array $object The name of the object * @param Connection $con The connection to use (specify Connection object to exert more control over transactions). * @return bool */ public function postDelete($object, $con = null) { if (!$object->isDeleted()) { return false; } $domain_id = 0; $changes = array(); if (get_class($object) == 'Record') { $peer_class = 'RecordPeer'; $domain_id = $object->getDomainId(); $classMapBuilder = 'RecordMapBuilder'; if (!($classPath = sfCore::getClassPath($classMapBuilder))) { throw new sfException(sprintf('Unable to find path for class "%s".', $classMapBuilder)); } require_once $classPath; $map = new $classMapBuilder(); $map->doBuild(); $tableMap = $map->getDatabaseMap()->getTable(constant($peer_class . '::TABLE_NAME')); foreach (call_user_func(array($peer_class, 'getFieldNames'), BasePeer::TYPE_COLNAME) as $column) { // do not keep track of changes for fields that are primary keys // or for the field 'updated_at' if ($tableMap->getColumn($column)->getColumnName() == 'UPDATED_AT') { continue; } if ($tableMap->getColumn($column)->isPrimaryKey()) { continue; } $column_phpname = call_user_func(array($peer_class, 'translateFieldName'), $column, BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME); $method = 'get' . sfInflector::camelize($column_phpname); $changes[$column_phpname] = $object->{$method}(); } } $this->save(get_class($object), $object->getPrimaryKey(), serialize($changes), $this->getLastQuery($con), self::TYPE_DELETE, $domain_id); }
require_once $sf_symfony_lib_dir . '/debug/sfTimer.class.php'; } // load base settings include $configCache->checkConfig($sf_app_config_dir_name . '/settings.yml'); if (sfConfig::get('sf_logging_enabled', true)) { include $configCache->checkConfig($sf_app_config_dir_name . '/logging.yml'); } if ($file = $configCache->checkConfig($sf_app_config_dir_name . '/app.yml', true)) { include $file; } if (sfConfig::get('sf_i18n')) { include $configCache->checkConfig($sf_app_config_dir_name . '/i18n.yml'); } // add autoloading callables foreach ((array) sfConfig::get('sf_autoloading_functions', array()) as $callable) { sfCore::addAutoloadCallable($callable); } // error settings ini_set('display_errors', $sf_debug ? 'on' : 'off'); error_reporting(sfConfig::get('sf_error_reporting')); // create bootstrap file for next time if (!sfConfig::get('sf_in_bootstrap') && !$sf_debug && !sfConfig::get('sf_test')) { $configCache->checkConfig($sf_app_config_dir_name . '/bootstrap_compile.yml'); } // required core classes for the framework // create a temp var to avoid substitution during compilation if (!$sf_debug && !sfConfig::get('sf_test')) { $core_classes = $sf_app_config_dir_name . '/core_compile.yml'; $configCache->import($core_classes, false); } $configCache->import($sf_app_config_dir_name . '/php.yml', false);
/** * Enable strict mode for development purposes. While in this mode, extra checks will be done * that may throw sfProgrammerExceptions. These checks may unnecessarily bog down runtime * speed during practical deployment, so leaving strict mode off can be useful. */ public static function enableStrictMode() { self::$strict = true; }
function __autoload($class) { return sfCore::splSimpleAutoload($class); }
/** * Loads the mappings for the classes * * @param string The model class name * * @throws sfException If the class cannot be found */ protected function loadMapBuilder($class) { $mapBuilderClass = $class . 'MapBuilder'; if (!isset($this->maps[$class])) { if (!($classPath = sfCore::getClassPath($mapBuilderClass))) { throw new sfException(sprintf('Unable to find path for class "%s".', $mapBuilderClass)); } require_once $classPath; $this->maps[$class] = new $mapBuilderClass(); $this->maps[$class]->doBuild(); } }
/** * Generate a new random key for this user. * * @return string 128-character generated key */ public function generateKey() { $sfUsers = sfCore::getClass('sfUsers'); do { $key = fCryptography::randomString(64); } while ($sfUsers::keyExists($key)); sfCore::$db->query("UPDATE `swoosh_users` SET `key`=%s WHERE `id`=%i", $key, $this->id); $this->key = $key; return $key; }
/** * Lazy-loading of parent post, just for when it's necessary. */ public function loadParentPost() { if (isset($this->parent)) { return $this->parent; } $this->parent = sfCore::make('sfBlogPost'); $this->parent->load($this->parent_id); return $this->parent; }