This repository has been archived by the owner on Apr 24, 2018. It is now read-only.
forked from AnimalDesign/bolt-shorturl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extension.php
executable file
·97 lines (80 loc) · 2.37 KB
/
Extension.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Bolt\Extension\rootLogin\Shorturl;
use Bolt\Application;
use Bolt\BaseExtension;
use Silex\Application as BoltApplication;
use Symfony\Component\HttpFoundation\Request;
class Extension extends BaseExtension
{
const NAME = 'Shorturl';
const CONTAINER = 'extensions.Shorturl';
/**
* Constructor adds an additional Twig path if we are in the Backend.
*
* @param Application $app
*/
public function __construct(Application $app)
{
parent::__construct($app);
$this->app['config']->getFields()->addField(new Field\ShorturlField());
}
public function initialize()
{
$this->app['twig.loader.filesystem']->prependPath(__DIR__."/twig");
$end = $this->app['config']->getWhichEnd();
$this->app->mount($this->app['config']->get('general/branding/path').'/async/shorturl', new Controller\AsyncController($this->app, $this->config));
if ($end =='backend') {
$this->addTwig();
$this->addCss('assets/css/field_shorturl.css');
$this->addJavascript('assets/js/field_shorturl.js', true);
} elseif($end == 'frontend') {
new Controller\ShorturlController($this->app);
}
}
/**
* Set the defaults for configuration parameters.
*
* @return array
*/
protected function getDefaultConfig()
{
return array(
'maxlength' => 10,
'prefix' => 's',
'checkunique' => true,
'host' => '*',
'destination' => 'link'
);
}
/**
* Add the Twig functions.
*/
private function addTwig()
{
$app = $this->app;
// Safe
$this->app->share(
$this->app->extend(
'twig',
function (\Twig_Environment $twig) use ($app) {
$twig->addExtension(new Twig\ShorturlExtension($app));
return $twig;
}
)
);
// Normal
$this->app->share(
$this->app->extend(
'safe_twig',
function (\Twig_Environment $twig) use ($app) {
$twig->addExtension(new Twig\ShorturlExtension($app));
return $twig;
}
)
);
}
public function getName()
{
return Extension::NAME;
}
}