init without trunk

This commit is contained in:
Kevin Adametz 2020-07-09 12:49:32 +02:00
parent ed24ac4994
commit bb809e7233
14652 changed files with 177862 additions and 94817 deletions

View file

@ -0,0 +1,124 @@
<?php
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Symfony\Bundle\AsseticBundle\Command;
use Assetic\Asset\AssetCollectionInterface;
use Assetic\Asset\AssetInterface;
use Assetic\Util\VarUtils;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
abstract class AbstractCommand extends ContainerAwareCommand
{
protected $am;
protected $basePath;
protected function initialize(InputInterface $input, OutputInterface $stdout)
{
$this->am = $this->getContainer()->get('assetic.asset_manager');
$this->basePath = $this->getContainer()->getParameter('assetic.write_to');
if ($input->hasArgument('write_to') && $basePath = $input->getArgument('write_to')) {
$this->basePath = $basePath;
}
}
/**
* Writes an asset.
*
* If the application or asset is in debug mode, each leaf asset will be
* dumped as well.
*
* @param string $name An asset name
* @param OutputInterface $stdout The command output
*/
public function dumpAsset($name, OutputInterface $stdout)
{
$asset = $this->am->get($name);
$formula = $this->am->hasFormula($name) ? $this->am->getFormula($name) : array();
// start by dumping the main asset
$this->doDump($asset, $stdout);
$debug = isset($formula[2]['debug']) ? $formula[2]['debug'] : $this->am->isDebug();
$combine = isset($formula[2]['combine']) ? $formula[2]['combine'] : !$debug;
// dump each leaf if no combine
if (!$combine) {
foreach ($asset as $leaf) {
$this->doDump($leaf, $stdout);
}
}
}
/**
* Performs the asset dump.
*
* @param AssetInterface $asset An asset
* @param OutputInterface $stdout The command output
*
* @throws RuntimeException If there is a problem writing the asset
*/
private function doDump(AssetInterface $asset, OutputInterface $stdout)
{
$combinations = VarUtils::getCombinations(
$asset->getVars(),
$this->getContainer()->getParameter('assetic.variables')
);
foreach ($combinations as $combination) {
$asset->setValues($combination);
// resolve the target path
$target = rtrim($this->basePath, '/').'/'.$asset->getTargetPath();
$target = str_replace('_controller/', '', $target);
$target = VarUtils::resolve($target, $asset->getVars(), $asset->getValues());
if (!is_dir($dir = dirname($target))) {
$stdout->writeln(sprintf(
'<comment>%s</comment> <info>[dir+]</info> %s',
date('H:i:s'),
$dir
));
if (false === @mkdir($dir, 0777, true)) {
throw new \RuntimeException('Unable to create directory '.$dir);
}
}
$stdout->writeln(sprintf(
'<comment>%s</comment> <info>[file+]</info> %s',
date('H:i:s'),
$target
));
if (OutputInterface::VERBOSITY_VERBOSE <= $stdout->getVerbosity()) {
if ($asset instanceof AssetCollectionInterface) {
foreach ($asset as $leaf) {
$root = $leaf->getSourceRoot();
$path = $leaf->getSourcePath();
$stdout->writeln(sprintf(' <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
}
} else {
$root = $asset->getSourceRoot();
$path = $asset->getSourcePath();
$stdout->writeln(sprintf(' <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
}
}
if (false === @file_put_contents($target, $asset->dump())) {
throw new \RuntimeException('Unable to write file '.$target);
}
}
}
}

View file

@ -0,0 +1,122 @@
<?php
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Symfony\Bundle\AsseticBundle\Command;
use Spork\Batch\Strategy\ChunkStrategy;
use Spork\EventDispatcher\WrappedEventDispatcher;
use Spork\ProcessManager;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Dumps assets to the filesystem.
*
* @author Kris Wallsmith <kris@symfony.com>
*/
class DumpCommand extends AbstractCommand
{
private $spork;
protected function configure()
{
$this
->setName('assetic:dump')
->setDescription('Dumps all assets to the filesystem')
->addArgument('write_to', InputArgument::OPTIONAL, 'Override the configured asset root')
->addOption('forks', null, InputOption::VALUE_REQUIRED, 'Fork work across many processes (requires kriswallsmith/spork)')
->addOption('watch', null, InputOption::VALUE_NONE, 'DEPRECATED: use assetic:watch instead')
->addOption('force', null, InputOption::VALUE_NONE, 'DEPRECATED: use assetic:watch instead')
->addOption('period', null, InputOption::VALUE_REQUIRED, 'DEPRECATED: use assetic:watch instead', 1)
;
}
protected function initialize(InputInterface $input, OutputInterface $stdout)
{
if (null !== $input->getOption('forks')) {
if (!class_exists('Spork\ProcessManager')) {
throw new \RuntimeException('The --forks option requires that package kriswallsmith/spork be installed');
}
if (!is_numeric($input->getOption('forks'))) {
throw new \InvalidArgumentException('The --forks options must be numeric');
}
$this->spork = new ProcessManager(
new WrappedEventDispatcher($this->getContainer()->get('event_dispatcher')),
null,
$this->getContainer()->getParameter('kernel.debug')
);
}
parent::initialize($input, $stdout);
}
protected function execute(InputInterface $input, OutputInterface $stdout)
{
// capture error output
$stderr = $stdout instanceof ConsoleOutputInterface
? $stdout->getErrorOutput()
: $stdout;
if ($input->getOption('watch')) {
$stderr->writeln(
'<error>The --watch option is deprecated. Please use the '.
'assetic:watch command instead.</error>'
);
// build assetic:watch arguments
$arguments = array(
'command' => 'assetic:watch',
'write_to' => $this->basePath,
'--period' => $input->getOption('period'),
'--env' => $input->getOption('env'),
);
if ($input->getOption('no-debug')) {
$arguments['--no-debug'] = true;
}
if ($input->getOption('force')) {
$arguments['--force'] = true;
}
$command = $this->getApplication()->find('assetic:watch');
return $command->run(new ArrayInput($arguments), $stdout);
}
// print the header
$stdout->writeln(sprintf('Dumping all <comment>%s</comment> assets.', $input->getOption('env')));
$stdout->writeln(sprintf('Debug mode is <comment>%s</comment>.', $this->am->isDebug() ? 'on' : 'off'));
$stdout->writeln('');
if ($this->spork) {
$batch = $this->spork->createBatchJob(
$this->am->getNames(),
new ChunkStrategy($input->getOption('forks'))
);
$self = $this;
$batch->execute(function ($name) use ($self, $stdout) {
$self->dumpAsset($name, $stdout);
});
} else {
foreach ($this->am->getNames() as $name) {
$this->dumpAsset($name, $stdout);
}
}
}
}

View file

@ -0,0 +1,123 @@
<?php
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Symfony\Bundle\AsseticBundle\Command;
use Assetic\Util\VarUtils;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Dumps assets as their source files are modified.
*
* @author Kris Wallsmith <kris@symfony.com>
*/
class WatchCommand extends AbstractCommand
{
protected function configure()
{
$this
->setName('assetic:watch')
->setDescription('Dumps assets to the filesystem as their source files are modified')
->addArgument('write_to', InputArgument::OPTIONAL, 'Override the configured asset root')
->addOption('force', null, InputOption::VALUE_NONE, 'Force an initial generation of all assets')
->addOption('period', null, InputOption::VALUE_REQUIRED, 'Set the polling period in seconds', 1)
;
}
protected function execute(InputInterface $input, OutputInterface $stdout)
{
// capture error output
$stderr = $stdout instanceof ConsoleOutputInterface
? $stdout->getErrorOutput()
: $stdout;
// print the header
$stdout->writeln(sprintf('Dumping all <comment>%s</comment> assets.', $input->getOption('env')));
$stdout->writeln(sprintf('Debug mode is <comment>%s</comment>.', $this->am->isDebug() ? 'on' : 'off'));
$stdout->writeln('');
// establish a temporary status file
$cache = sys_get_temp_dir().'/assetic_watch_'.substr(sha1($this->basePath), 0, 7);
if ($input->getOption('force') || !file_exists($cache)) {
$previously = array();
} else {
$previously = unserialize(file_get_contents($cache));
if (!is_array($previously)) {
$previously = array();
}
}
$error = '';
while (true) {
try {
foreach ($this->am->getNames() as $name) {
if ($this->checkAsset($name, $previously)) {
$this->dumpAsset($name, $stdout);
}
}
// reset the asset manager
$this->am->clear();
$this->am->load();
file_put_contents($cache, serialize($previously));
$error = '';
} catch (\Exception $e) {
if ($error != $msg = $e->getMessage()) {
$stderr->writeln('<error>[error]</error> '.$msg);
$error = $msg;
}
}
clearstatcache ();
sleep($input->getOption('period'));
}
}
/**
* Checks if an asset should be dumped.
*
* @param string $name The asset name
* @param array &$previously An array of previous visits
*
* @return Boolean Whether the asset should be dumped
*/
private function checkAsset($name, array &$previously)
{
$formula = $this->am->hasFormula($name) ? serialize($this->am->getFormula($name)) : null;
$asset = $this->am->get($name);
$combinations = VarUtils::getCombinations(
$asset->getVars(),
$this->getContainer()->getParameter('assetic.variables')
);
$mtime = 0;
foreach ($combinations as $combination) {
$asset->setValues($combination);
$mtime = max($mtime, $this->am->getLastModified($asset));
}
if (isset($previously[$name])) {
$changed = $previously[$name]['mtime'] != $mtime || $previously[$name]['formula'] != $formula;
} else {
$changed = true;
}
$previously[$name] = array('mtime' => $mtime, 'formula' => $formula);
return $changed;
}
}