|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of BraincraftedBootstrapBundle. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2012-2013 by Florian Eckerstorfer |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Braincrafted\Bundle\BootstrapBundle\Command; |
|
10
|
|
|
|
|
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
|
|
15
|
|
|
use Braincrafted\Bundle\BootstrapBundle\Util\PathUtil; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
17
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* GenerateCommand |
|
21
|
|
|
* |
|
22
|
|
|
* @package BraincraftedBootstrapBundle |
|
23
|
|
|
* @subpackage Command |
|
24
|
|
|
* @author Florian Eckerstorfer <[email protected]> |
|
25
|
|
|
* @copyright 2012-2013 Florian Eckerstorfer |
|
26
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License |
|
27
|
|
|
* @link http://bootstrap.braincrafted.com BraincraftedBootstrapBundle |
|
28
|
|
|
*/ |
|
29
|
|
|
class GenerateCommand extends ContainerAwareCommand |
|
30
|
|
|
{ |
|
31
|
|
|
/** @var PathUtil */ |
|
32
|
|
|
private $pathUtil; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritDoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct($name = null) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->pathUtil = new PathUtil; |
|
40
|
|
|
|
|
41
|
|
|
parent::__construct($name); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritDoc} |
|
46
|
|
|
* |
|
47
|
|
|
* @codeCoverageIgnore |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function configure() |
|
50
|
|
|
{ |
|
51
|
|
|
$this |
|
52
|
|
|
->setName('braincrafted:bootstrap:generate') |
|
53
|
|
|
->setDescription('Generates a custom bootstrap.less') |
|
54
|
|
|
; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritDoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
61
|
|
|
{ |
|
62
|
|
|
$config = $this->getContainer()->getParameter('braincrafted_bootstrap.customize'); |
|
63
|
|
|
|
|
64
|
|
|
if (false === isset($config['variables_file']) || null === $config['variables_file']) { |
|
65
|
|
|
$output->writeln('<error>Found no custom variables.less file.</error>'); |
|
66
|
|
|
|
|
67
|
|
|
return; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$filter = $this->getContainer()->getParameter('braincrafted_bootstrap.css_preprocessor'); |
|
71
|
|
|
if ('less' !== $filter && 'lessphp' !== $filter) { |
|
72
|
|
|
$output->writeln( |
|
73
|
|
|
'<error>Bundle must be configured with "less" or "lessphp" to generated bootstrap.less</error>' |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
return; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$output->writeln('<comment>Found custom variables file. Generating...</comment>'); |
|
80
|
|
|
$this->executeGenerateBootstrap($config); |
|
81
|
|
|
$output->writeln(sprintf('Saved to <info>%s</info>', $config['bootstrap_output'])); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
protected function executeGenerateBootstrap(array $config) |
|
85
|
|
|
{ |
|
86
|
|
|
// In the template for bootstrap.less we need the path where Bootstraps .less files are stored and the path |
|
87
|
|
|
// to the variables.less file. |
|
88
|
|
|
// Absolute path do not work in LESSs import statement, we have to calculate the relative ones |
|
89
|
|
|
|
|
90
|
|
|
$lessDir = $this->pathUtil->getRelativePath( |
|
91
|
|
|
dirname($config['bootstrap_output']), |
|
92
|
|
|
$this->getContainer()->getParameter('braincrafted_bootstrap.assets_dir') |
|
93
|
|
|
); |
|
94
|
|
|
$variablesDir = $this->pathUtil->getRelativePath( |
|
95
|
|
|
dirname($config['bootstrap_output']), |
|
96
|
|
|
dirname($config['variables_file']) |
|
97
|
|
|
); |
|
98
|
|
|
$variablesFile = sprintf( |
|
99
|
|
|
'%s%s%s', |
|
100
|
|
|
$variablesDir, |
|
101
|
|
|
strlen($variablesDir) > 0 ? '/' : '', |
|
102
|
|
|
basename($config['variables_file']) |
|
103
|
|
|
); |
|
104
|
|
|
|
|
105
|
|
|
$container = $this->getContainer(); |
|
106
|
|
|
|
|
107
|
|
|
if (Kernel::VERSION_ID >= 20500 && Kernel::VERSION_ID < 30000) { |
|
108
|
|
|
$container->enterScope('request'); |
|
|
|
|
|
|
109
|
|
|
$container->set('request', new Request(), 'request'); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
// We can now use Twig to render the bootstrap.less file and save it |
|
113
|
|
|
$content = $container->get('twig')->render( |
|
114
|
|
|
$config['bootstrap_template'], |
|
115
|
|
|
array( |
|
116
|
|
|
'variables_file' => $variablesFile, |
|
117
|
|
|
'assets_dir' => $lessDir |
|
118
|
|
|
) |
|
119
|
|
|
); |
|
120
|
|
|
file_put_contents($config['bootstrap_output'], $content); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.