![]() |
|
Snippets |
|
It can be a hassle to write a package.yml for a plugin if it contains many files. Fortunately, with the help of the sfFinder class and a bit of programming, you can automate the generation of the <content> part in a batch.
Create a batch/package_generator.php with the following code:
<?php define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..')); define('SF_APP', 'frontend'); define('SF_ENVIRONMENT', 'prod'); define('SF_DEBUG', false); require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php'); $line = array(); $lines = array(); $previous_dirs = array(); $files = sfFinder::type('file')->relative()->in('path/to/plugin/files'); // Prepare the list of files for nice hierarchy foreach($files as $file) { $file = str_replace('\\', '/', $file); $dirs = explode ('/', $file); $line['filename'] = array_pop($dirs); $temp_dirs = $dirs; foreach($dirs as $dir) { if($previous_dirs && $dir == $previous_dirs[0]) { array_shift($previous_dirs); array_shift($dirs); } } foreach($dirs as $dir) { $line['open'][] = $dir; } foreach($previous_dirs as $dir) { $line['close'][] = $dir; } $lines[] = $line; $line = array(); $previous_dirs = $temp_dirs; } $blanks = 0; ?> <?php foreach($lines as $line): ?> <?php if(isset($line['close'])): ?> <?php foreach($line['close'] as $dir): ?> <?php echo str_repeat(' ', --$blanks) ?></dir> <?php endforeach; ?> <?php endif; ?> <?php if(isset($line['open'])): ?> <?php foreach($line['open'] as $dir): $counter++ ?> <?php echo str_repeat(' ', $blanks++) ?><dir name="<?php echo $dir ?>"> <?php endforeach; ?> <?php endif; ?> <?php echo str_repeat(' ', $blanks) ?><file name="<?php echo str_replace('\\', '/', $line['filename']) ?>" role="data"/> <?php endforeach; ?>
Just run it with
> php batch/package_generator.php
and paste the output in your package.xml. That's all.