-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGalileoExtension.php
51 lines (40 loc) · 1.95 KB
/
GalileoExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Galileo;
use Exception,
Nette\DI\CompilerExtension,
Nette\PhpGenerator\ClassType;
final class GalileoExtension extends CompilerExtension {
/** @var array */
private $defaults = ['assets' => '/assets/galileo/'];
/** @var array */
private $parameters;
public function afterCompile(ClassType $class) {
$initialize = $class->methods['initialize'];
$initialize->addBody('Nette\Forms\Container::extensionMethod("\Nette\Forms\Container::addSeznamMap", '
. 'function (\Nette\Forms\Container $_this, string $name, string $label) { '
. 'return $_this[$name] = new Galileo\AddMap("' . $this->parameters['galileo']['assets'] . '", $name, $label, $this->getByType(?)); });',
['Nette\Http\IRequest']);
}
public function beforeCompile() {
if(!class_exists('Nette\Application\Application')) {
throw new MissingDependencyException('Please install and enable https://github.com/nette/nette.');
}
parent::beforeCompile();
}
public function getConfiguration(array $parameters) {
foreach($this->defaults as $key => $parameter) {
if(!isset($parameters['galileo'][$key])) {
$parameters['galileo'][$key] = $parameter;
}
}
return $parameters;
}
public function loadConfiguration() {
$builder = $this->getContainerBuilder();
$this->parameters = $this->getConfiguration($builder->parameters);
$builder->addDefinition($this->prefix('seznamMap'))->setFactory('Galileo\SeznamMap', [$this->parameters['galileo']['assets']]);
$builder->addDefinition($this->prefix('svgMap'))->setFactory('Galileo\SvgMap', [$this->parameters['galileo']['assets']]);
$builder->addDefinition($this->prefix('galileoExtension'))->setFactory('Galileo\GalileoExtension', []);
}
}
class MissingDependencyException extends Exception { }