Make builder service stateless

This commit is contained in:
Nicolas Le Goff
2013-07-10 11:41:34 +02:00
parent c163f6c4ce
commit 648ed30bb9
3 changed files with 16 additions and 30 deletions

View File

@@ -12,7 +12,6 @@
namespace Alchemy\Phrasea\Command\Developer; namespace Alchemy\Phrasea\Command\Developer;
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Utilities\Compiler\RecessLessCompiler;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
@@ -21,16 +20,11 @@ use Symfony\Component\Console\Output\OutputInterface;
*/ */
class LessCompiler extends Command class LessCompiler extends Command
{ {
private $recessLessCompiler; public function __construct()
public function __construct($recessLessCompiler = null)
{ {
parent::__construct('assets:compile-less'); parent::__construct('assets:compile-less');
$this->setDescription('Compile less files'); $this->setDescription('Compile less files');
$this->recessLessCompiler = $recessLessCompiler ?: new RecessLessCompiler();
} }
/** /**
@@ -57,8 +51,10 @@ class LessCompiler extends Command
$output->writeln('Building Assets...'); $output->writeln('Building Assets...');
if (false === $this->container['phraseanet.less-builder']->build($files)) { $errors = $this->container['phraseanet.less-builder']->build($files);
$output->writeln(sprintf('<error>Errors occured during the build %s</error>', implode(', ', $this->container['phraseanet.less-builder']->getErrors())));
if (count($errors) > 0) {
$output->writeln(sprintf('<error>Errors occured during the build %s</error>', implode(', ', $errors)));
return 1; return 1;
} }

View File

@@ -38,12 +38,16 @@ abstract class AbstractPluginCommand extends Command
$this->container['plugins.autoloader-generator']->write($manifests); $this->container['plugins.autoloader-generator']->write($manifests);
$output->writeln(" <comment>OK</comment>"); $output->writeln(" <comment>OK</comment>");
$output->write('Building Assets...'); $files = array(
if (false === $this->container['phraseanet.less-builder']->build(array(
$this->container['root.path'] . '/www/skins/login/less/login.less' => $this->container['root.path'] . '/www/skins/build/login.css', $this->container['root.path'] . '/www/skins/login/less/login.less' => $this->container['root.path'] . '/www/skins/build/login.css',
$this->container['root.path'] . '/www/skins/account/account.less' => $this->container['root.path'] . '/www/skins/build/account.css', $this->container['root.path'] . '/www/skins/account/account.less' => $this->container['root.path'] . '/www/skins/build/account.css',
))) { );
$output->writeln(sprintf('<error>Error(s) occured during the build %s</error>', implode(', ', $this->container['phraseanet.less-builder']->getErrors())));
$output->write('Building Assets...');
$errors = $this->container['phraseanet.less-builder']->build($files);
if (count($errors) > 0) {
$output->writeln(sprintf('<error>Error(s) occured during the build %s</error>', implode(', ', $errors)));
} }
$output->writeln(" <comment>OK</comment>"); $output->writeln(" <comment>OK</comment>");
} }

View File

@@ -24,10 +24,6 @@ class Builder
* @var Filesystem * @var Filesystem
*/ */
protected $filesystem; protected $filesystem;
/**
* @var array
*/
protected $errors = array();
public function __construct(LessCompiler $compiler, Filesystem $filesystem) public function __construct(LessCompiler $compiler, Filesystem $filesystem)
{ {
@@ -43,7 +39,7 @@ class Builder
public function build($files) public function build($files)
{ {
$failures = 0; $failures = 0;
$this->errors = array(); $errors = array();
foreach ($files as $lessFile => $target) { foreach ($files as $lessFile => $target) {
$this->filesystem->mkdir(dirname($target)); $this->filesystem->mkdir(dirname($target));
@@ -52,20 +48,10 @@ class Builder
$this->compiler->compile($target, $lessFile); $this->compiler->compile($target, $lessFile);
} catch (\Exception $e) { } catch (\Exception $e) {
$failures++; $failures++;
$this->errors[] = $e->getMessage(); $errors[] = $e->getMessage();
} }
} }
return $this->hasErrors(); return $errors;
}
public function hasErrors()
{
return count($this->errors) === 0;
}
public function getErrors()
{
return $this->errors;
} }
} }