Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 96 lines (85 sloc) 2.52 kB
300f9b1 @simensen Initial import.
simensen authored
1 <?php
51674ac @simensen Tweak some mac format issues, now deals with cache.
simensen authored
2
3 /*
4 * This file is a part of Twig GitHub Gist Sculpin Bundle.
5 *
6 * (c) Dragonfly Development Inc.
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
300f9b1 @simensen Initial import.
simensen authored
11
5e2df96 @simensen More changes for new bundle naming.
simensen authored
12 namespace Dflydev\Sculpin\Bundle\TwigGitHubGistBundle;
300f9b1 @simensen Initial import.
simensen authored
13
14 use dflydev\twig\extension\gitHub\gist\cache\FilesystemCache;
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
15 use dflydev\twig\extension\gitHub\gist\GistTwigExtension;
300f9b1 @simensen Initial import.
simensen authored
16 use sculpin\bundle\AbstractBundle;
17 use sculpin\bundle\twigBundle\TwigBundle;
18 use sculpin\bundle\twigBundle\TwigFormatter;
51674ac @simensen Tweak some mac format issues, now deals with cache.
simensen authored
19 use sculpin\console\Application;
20 use sculpin\formatter\IFormatter;
300f9b1 @simensen Initial import.
simensen authored
21 use sculpin\Sculpin;
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
22 use Symfony\Component\Console\Input\InputInterface;
23 use Symfony\Component\Console\Output\OutputInterface;
300f9b1 @simensen Initial import.
simensen authored
24
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
25 /**
26 * Twig GitHub Gist Bundle
27 *
28 * @author Beau Simensen <beau@dflydev.com>
29 */
300f9b1 @simensen Initial import.
simensen authored
30 class TwigGitHubGistBundle extends AbstractBundle
31 {
32 /**
33 * Is this bundle enabled?
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
34 *
300f9b1 @simensen Initial import.
simensen authored
35 * @var string
36 */
37 const CONFIG_ENABLED = 'twig_github_gist.enabled';
38
39 /**
40 * Is cache enabled?
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
41 *
300f9b1 @simensen Initial import.
simensen authored
42 * @var string
43 */
44 const CONFIG_CACHE_ENABLED = 'twig_github_gist.cache.enabled';
45
46 /**
47 * Name of cache directory
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
48 *
300f9b1 @simensen Initial import.
simensen authored
49 * @var string
50 */
51 const CONFIG_CACHE_DIRECTORY = 'twig_github_gist.cache.directory';
52
53 /**
54 * Cache directory
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
55 *
300f9b1 @simensen Initial import.
simensen authored
56 * @var string
57 */
58 protected $cacheDirectory;
59
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
60
300f9b1 @simensen Initial import.
simensen authored
61 /**
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
62 * {@inheritdoc}
51674ac @simensen Tweak some mac format issues, now deals with cache.
simensen authored
63 */
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
64 public function boot()
300f9b1 @simensen Initial import.
simensen authored
65 {
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
66 if ($this->configuration->get(self::CONFIG_ENABLED)) {
43ecc2e @simensen Missed some variables in the conversion.
simensen authored
67 $this->cacheDirectory = $this->sculpin->prepareCacheFor(
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
68 $this->configuration->get(self::CONFIG_CACHE_DIRECTORY)
69 );
43ecc2e @simensen Missed some variables in the conversion.
simensen authored
70 $this->sculpin->registerFormatterConfigurationCallback(
300f9b1 @simensen Initial import.
simensen authored
71 TwigBundle::FORMATTER_NAME,
72 array($this, 'configureTwigFormatter')
73 );
74 }
75 }
76
77 /**
78 * Configure Twig formatter callback
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
79 *
80 * @param Sculpin $sculpin Sculpin
81 * @param IFormatter $formatter Formatter
300f9b1 @simensen Initial import.
simensen authored
82 */
51674ac @simensen Tweak some mac format issues, now deals with cache.
simensen authored
83 public function configureTwigFormatter(Sculpin $sculpin, IFormatter $formatter)
300f9b1 @simensen Initial import.
simensen authored
84 {
85 if ($formatter instanceof TwigFormatter) {
43ecc2e @simensen Missed some variables in the conversion.
simensen authored
86 if ($this->configuration->get(self::CONFIG_CACHE_ENABLED)) {
300f9b1 @simensen Initial import.
simensen authored
87 $cache = new FilesystemCache($this->cacheDirectory);
88 } else {
89 $cache = null;
90 }
91 $gistTwigExtension = new GistTwigExtension(null, $cache);
92 $formatter->twig()->addExtension($gistTwigExtension);
51674ac @simensen Tweak some mac format issues, now deals with cache.
simensen authored
93 }
300f9b1 @simensen Initial import.
simensen authored
94 }
4197b24 @simensen Account for new changes to Sculpin.
simensen authored
95 }
Something went wrong with that request. Please try again.