/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $filename = $arguments['target']; if (null !== $filename && !sfToolkit::isPathAbsolute($filename)) { $dir = sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'fixtures'; $this->getFilesystem()->mkdirs($dir); $filename = $dir.DIRECTORY_SEPARATOR.$filename; $this->logSection('propel', sprintf('dumping data to "%s"', $filename)); } $data = new sfPropelData(); $classes = null === $options['classes'] ? 'all' : explode(',', $options['classes']); if (null !== $filename) { $data->dumpData($filename, $classes, $options['connection']); } else { fwrite(STDOUT, sfYaml::dump($data->getData($classes, $options['connection']), 3)); } }
/** * La funcion original en dist/symfony/data/tasks/sfPakePropel.php * NO FUNCIONA * porque a la funcion dumpData() no se le pasan los parametros correctos * * * Dumps yml database data to fixtures directory. * * @example symfony dump-data frontend data.yml * @example symfony dump-data frontend data.yml dev * * @param object $task * @param array $args */ function run_alba_dump_data($task, $args) { if (!count($args)) { throw new Exception('You must provide the app.'); } $app = $args[0]; if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) { throw new Exception('The app "' . $app . '" does not exist.'); } if (!isset($args[1])) { throw new Exception('You must provide a filename.'); } $filename = $args[1]; $env = empty($args[2]) ? 'dev' : $args[2]; // define constants define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', $app); define('SF_ENVIRONMENT', $env); define('SF_DEBUG', true); // get configuration require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); if (!sfToolkit::isPathAbsolute($filename)) { $dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'fixtures'; pake_mkdirs($dir); $filename = $dir . DIRECTORY_SEPARATOR . $filename; } pake_echo_action('propel', sprintf('dumping data to "%s"', $filename)); $data = new sfPropelData(); // FIX de parametros $data->dumpData($filename, 'all', 'alba'); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $config = $this->getCliConfig(); $args = array( 'data_fixtures_path' => $config['data_fixtures_path'][0], ); if (!is_dir($args['data_fixtures_path'])) { $this->getFilesystem()->mkdirs($args['data_fixtures_path']); } if ($arguments['target']) { $filename = $arguments['target']; if (!sfToolkit::isPathAbsolute($filename)) { $filename = $args['data_fixtures_path'].'/'.$filename; } $this->getFilesystem()->mkdirs(dirname($filename)); $args['data_fixtures_path'] = $filename; } $this->logSection('doctrine', sprintf('dumping data to fixtures to "%s"', $args['data_fixtures_path'])); $this->callDoctrineCli('dump-data', $args); }
/** * Replaces a relative filesystem path with an absolute one. * * @param string A relative filesystem path * * @return string The new path */ public static function replacePath($path) { if (!sfToolkit::isPathAbsolute($path)) { // not an absolute path so we'll prepend to it $path = sfConfig::get('sf_app_dir') . '/' . $path; } return $path; }
/** * Sets the template for this view. * * If the template path is relative, it will be based on the currently * executing module's template sub-directory. * * @param string $template An absolute or relative filesystem path to a template */ public function setTemplate($template) { if (sfToolkit::isPathAbsolute($template)) { print ">>>1"; $this->directory = dirname($template); $this->template = basename($template); } else { print ">>>2"; $this->directory = $this->context->getConfiguration()->getTemplateDir($this->moduleName, $template); $this->template = $template; } }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $args = array(); if (isset($arguments['target'])) { $filename = $arguments['target']; if (!sfToolkit::isPathAbsolute($filename)) { $dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'fixtures'; $filename = $dir . DIRECTORY_SEPARATOR . $filename; } $args = array('data_fixtures_path' => $filename); } $this->callDoctrineCli('dump-data', $args); }
/** * Sets a Subversion property on a path. * * @param string $property * @param string|array $value * @param string|array $path */ protected function setSubversionProperty($property, $value, $path) { if (!is_array($value)) { $value = array($value); } if (!is_array($path)) { $path = array($path); } $file = tempnam(sys_get_temp_dir(), 'sf_'); $this->logSection('file+', $file); file_put_contents($file, implode(PHP_EOL, $value)); foreach ($path as $p) { $this->getFilesystem()->execute(vsprintf('%s propset %s -F %s %s', array($this->subversionBinary, $property, escapeshellarg($file), escapeshellarg(!sfToolkit::isPathAbsolute($p) ? sfConfig::get('sf_root_dir') . '/' . $p : $p)))); } $this->getFilesystem()->remove($file); }
protected function _findLayoutPath($layout = null) { if ($layout === null) { $layout = $this->getName(); } $sympalConfiguration = sfSympalContext::getInstance()->getSympalConfiguration(); $layouts = $sympalConfiguration->getLayouts(); $path = array_search($layout, $layouts); if (!$path) { throw new InvalidArgumentException(sprintf('Could not find layout path for theme "%s"', $layout)); } if (!sfToolkit::isPathAbsolute($path)) { $path = sfConfig::get('sf_root_dir') . '/' . $path; } return $path; }
/** * Sets a Subversion property on a path. * * @param string $property * @param string|array $value * @param string|array $path */ protected function setSubversionProperty($property, $value, $path) { if (!is_array($value)) { $value = array($value); } if (!is_array($path)) { $path = array($path); } $file = sys_get_temp_dir() . 'sf_' . md5(rand(11111, 99999)); $this->getFilesystem()->touch($file); file_put_contents($file, join(PHP_EOL, $value)); foreach ($path as $p) { $this->getFilesystem()->sh(vsprintf('%s propset %s -F %s %s', array($this->subversionBinary, $property, escapeshellarg($file), escapeshellarg(!sfToolkit::isPathAbsolute($p) ? sfConfig::get('sf_root_dir') . '/' . $p : $p)))); } $this->getFilesystem()->remove($file); }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $config = $this->getCliConfig(); $dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'fixtures'; Doctrine_Lib::makeDirectories($dir); $args = array(); if (isset($arguments['target'])) { $filename = $arguments['target']; if (!sfToolkit::isPathAbsolute($filename)) { $filename = $dir . DIRECTORY_SEPARATOR . $filename; } Doctrine_Lib::makeDirectories(dirname($filename)); $args = array('data_fixtures_path' => array($filename)); $this->logSection('doctrine', sprintf('dumping data to fixtures to "%s"', $filename)); } else { $this->logSection('doctrine', sprintf('dumping data to fixtures to "%s"', $config['data_fixtures_path'][0])); } $this->callDoctrineCli('dump-data', $args); }
/** * Get the path to the file to backup * * @param array $arguments Arguments for this task * @param array $options Options for this task * @param string $filenameSuffix (Optional) A suffix for the end of the * filename * @param string $databaseName (Optional) The database connection name * @param boolean $multipleDatabases (Optional) Whether there are multiple * databases * * @return string */ protected function getBackupPath(array $arguments, array $options, $filenameSuffix = '', $databaseName = '', $multipleDatabases = false) { $config = $this->getCliConfig(); $sqlPath = $config['sql_path']; if (!is_dir($sqlPath)) { $this->getFilesystem()->mkdirs($sqlPath); } $path = $sqlPath; if ($arguments['target']) { $filename = $arguments['target']; if (!sfToolkit::isPathAbsolute($filename)) { $filename = $sqlPath . '/' . $filename; } $this->getFilesystem()->mkdirs(dirname($filename)); $path = $filename; } if (is_dir($path)) { // create filename for backup $path = rtrim($path, '/') . '/' . date(sfConfig::get('app_sfDoctrineMysqlSafeMigratePlugin_dump_date_format', 'U')) . ($filenameSuffix ? '_' . $filenameSuffix : '') . ($multipleDatabases ? '_' . $databaseName : '') . '.sql'; } return $path; }
public function setTemplate($template) { if (sfToolkit::isPathAbsolute($template)) { $this->directory = dirname($template); $this->template = basename($template); } else { $this->template = $template; } }
/** * Checks to see if a configuration file has been modified and if so * recompile the cache file associated with it. * * The recompilation only occurs in a non debug environment. * * If the configuration file path is relative, symfony will look in directories * defined in the sfConfiguration::getConfigPaths() method. * * @param string $configPath A filesystem path to a configuration file * @param boolean $optional If true, config path does not need to exist * * @return string An absolute filesystem path to the cache filename associated with this specified configuration file * * @throws <b>sfConfigurationException</b> If a requested configuration file does not exist * * @see sfConfiguration::getConfigPaths() */ public function checkConfig($configPath, $optional = false) { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer('Configuration'); } // the cache filename we'll be using $cache = $this->getCacheName($configPath); if (!sfConfig::get('sf_debug') && !sfConfig::get('sf_test') && is_readable($cache)) { return $cache; } if (!sfToolkit::isPathAbsolute($configPath)) { $files = $this->configuration->getConfigPaths($configPath); } else { $files = is_readable($configPath) ? array($configPath) : array(); } if (!isset($files[0])) { if ($optional) { return null; } // configuration does not exist throw new sfConfigurationException(sprintf('Configuration "%s" does not exist or is unreadable.', $configPath)); } // find the more recent configuration file last modification time $mtime = 0; foreach ($files as $file) { if (filemtime($file) > $mtime) { $mtime = filemtime($file); } } if (!is_readable($cache) || $mtime > filemtime($cache)) { // configuration has changed so we need to reparse it $this->callHandler($configPath, $files, $cache); } if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return $cache; }
$t->is(sfToolkit::replaceConstants('%Y/%m/%d %H:%M'), '%Y/%m/%d %H:%M', '::replaceConstantsCallback() does not replace unknown constants'); sfConfig::set('bar', null); $t->is(sfToolkit::replaceConstants('my value with a %bar% constant'), 'my value with a constant', '::replaceConstantsCallback() replaces constants enclosed in % even if value is null'); $t->is(sfToolkit::replaceConstants('my value with a %foobar% constant'), 'my value with a %foobar% constant', '::replaceConstantsCallback() returns the original string if the constant is not defined'); $t->is(sfToolkit::replaceConstants('my value with a %foo\'bar% constant'), 'my value with a %foo\'bar% constant', '::replaceConstantsCallback() returns the original string if the constant is not defined'); $t->is(sfToolkit::replaceConstants('my value with a %foo"bar% constant'), 'my value with a %foo"bar% constant', '::replaceConstantsCallback() returns the original string if the constant is not defined'); // ::isPathAbsolute() $t->diag('::isPathAbsolute()'); $t->is(sfToolkit::isPathAbsolute('/test'), true, '::isPathAbsolute() returns true if path is absolute'); $t->is(sfToolkit::isPathAbsolute('\\test'), true, '::isPathAbsolute() returns true if path is absolute'); $t->is(sfToolkit::isPathAbsolute('C:\\test'), true, '::isPathAbsolute() returns true if path is absolute'); $t->is(sfToolkit::isPathAbsolute('d:/test'), true, '::isPathAbsolute() returns true if path is absolute'); $t->is(sfToolkit::isPathAbsolute('test'), false, '::isPathAbsolute() returns false if path is relative'); $t->is(sfToolkit::isPathAbsolute('../test'), false, '::isPathAbsolute() returns false if path is relative'); $t->is(sfToolkit::isPathAbsolute('..\\test'), false, '::isPathAbsolute() returns false if path is relative'); // ::stripComments() $t->diag('::stripComments()'); $php = <<<EOF <?php # A perl like comment // Another comment /* A very long comment on several lines */ \$i = 1; // A comment on a PHP line
/** * Replaces a relative filesystem path with an absolute one. * * @param string $path A relative filesystem path * * @return string The new path */ public static function replacePath($path) { if (is_array($path)) { array_walk_recursive($path, create_function('&$path', '$path = sfConfigHandler::replacePath($path);')); } else { if (!sfToolkit::isPathAbsolute($path)) { // not an absolute path so we'll prepend to it $path = sfConfig::get('sf_app_dir') . '/' . $path; } } return $path; }
/** * Checks to see if a configuration file has been modified and if so * recompile the cache file associated with it. * * The recompilation only occurs in a non debug environment. * * If the configuration file path is relative, symfony will look in directories * defined in the sfLoader::getConfigPaths() method. * * @param string A filesystem path to a configuration file * * @return string An absolute filesystem path to the cache filename associated with this specified configuration file * * @throws <b>sfConfigurationException</b> If a requested configuration file does not exist * * @see sfLoader::getConfigPaths() */ public function checkConfig($configPath, $optional = false) { static $process_cache_cleared = false; if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer = sfTimerManager::getTimer('Configuration'); } // the cache filename we'll be using $cache = $this->getCacheName($configPath); if (sfConfig::get('sf_in_bootstrap') && is_readable($cache)) { if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return $cache; } if (!sfToolkit::isPathAbsolute($configPath)) { $files = sfLoader::getConfigPaths($configPath); } else { $files = is_readable($configPath) ? array($configPath) : array(); } if (!isset($files[0])) { if ($optional) { return null; } // configuration does not exist $error = sprintf('Configuration "%s" does not exist or is unreadable', $configPath); throw new sfConfigurationException($error); } // find the more recent configuration file last modification time $mtime = 0; foreach ($files as $file) { if (filemtime($file) > $mtime) { $mtime = filemtime($file); } } if (!is_readable($cache) || $mtime > filemtime($cache)) { // configuration has changed so we need to reparse it $this->callHandler($configPath, $files, $cache); // clear process cache if ('config/config_handlers.yml' != $configPath && sfConfig::get('sf_use_process_cache') && !$process_cache_cleared) { sfProcessCache::clear(); $process_cache_cleared = true; } } if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) { $timer->addTime(); } return $cache; }
function _absolute_path_difference($source, $target) { if (!function_exists('symlink') || !sfToolkit::isPathAbsolute($source) || !sfToolkit::isPathAbsolute($target)) { return $target; } $source = explode(DIRECTORY_SEPARATOR, rtrim($source, DIRECTORY_SEPARATOR)); $target = explode(DIRECTORY_SEPARATOR, rtrim($target, DIRECTORY_SEPARATOR)); if ($source == $target) { return '.'; } for ($i = 0; $i < count($source); $i++) { if (!isset($target[$i]) || $target[$i] != $source[$i]) { $source_path_diff = array_fill(0, count($source) - $i, '..'); $target_path_diff = array_slice($target, $i); $merge = array_merge($source_path_diff, $target_path_diff); return join(DIRECTORY_SEPARATOR, $merge); } } return join(DIRECTORY_SEPARATOR, array_slice($target, count($source))); }
/** * Calculates the location of a layout, which could live in several locations. * * Specifically, the layout file for a theme could live in any "templates" * file found in the application dir or any enabled plugins */ protected function _findLayoutPath($layout) { $layouts = $this->_getThemeToolkit()->getLayouts(); $path = array_search($layout, $layouts); if (!$path) { throw new InvalidArgumentException(sprintf('Could not find layout "%s" in any "templates" directories. You may need to clear your cache.', $layout)); } if (!sfToolkit::isPathAbsolute($path)) { $path = sfConfig::get('sf_root_dir') . '/' . $path; } return $path; }
/** * Formats a file link. * * @param string $file A file path or class name * @param integer $line * @param string $text Text to use for the link * * @return string */ public function formatFileLink($file, $line = null, $text = null) { // this method is called a lot so we avoid calling class_exists() if ($file && !sfToolkit::isPathAbsolute($file)) { if (null === $text) { $text = $file; } // translate class to file name $r = new ReflectionClass($file); $file = $r->getFileName(); } $shortFile = sfDebug::shortenFilePath($file); if ($linkFormat = sfConfig::get('sf_file_link_format', ini_get('xdebug.file_link_format'))) { // return a link return sprintf( '<a href="%s" class="sfWebDebugFileLink" title="%s">%s</a>', htmlspecialchars(strtr($linkFormat, array('%f' => $file, '%l' => $line)), ENT_QUOTES, sfConfig::get('sf_charset')), htmlspecialchars($shortFile, ENT_QUOTES, sfConfig::get('sf_charset')), null === $text ? $shortFile : $text); } else if (null === $text) { // return the shortened file path return $shortFile; } else { // return the provided text with the shortened file path as a tooltip return sprintf('<span title="%s">%s</span>', $shortFile, $text); } }
/** * run_doctrine_dump_data * * @param mixed $task * @param mixed $args * @access public * @return void */ function run_doctrine_dump_data($task, $args) { if (!count($args)) { throw new Exception('You must provide the app.'); } $app = $args[0]; if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) { throw new Exception('The app "' . $app . '" does not exist.'); } if (!isset($args[1])) { throw new Exception('You must provide a filename.'); } $filename = $args[1]; $env = empty($args[2]) ? 'dev' : $args[2]; _load_application_environment($app, $env); if (!sfToolkit::isPathAbsolute($filename)) { $dir = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . 'fixtures'; pake_mkdirs($dir); $filename = $dir . DIRECTORY_SEPARATOR . $filename; } pake_echo_action('doctrine', sprintf('dumping data to "%s"', $filename)); $data = new sfDoctrineData(); $data->dumpData($filename); }