From 8ac31cdc930338b8d824a69f5be95ade8e189a8f Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Thu, 7 Jun 2012 00:55:56 -0300 Subject: [PATCH] Adding support to syntax highlighting for custom extensions, fixes #34. Thanks @attiks --- index.php | 1 + lib/Application/Utils.php | 19 +++++++++++++++++-- lib/Application/UtilsServiceProvider.php | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 037f878..a2d1e8a 100644 --- a/index.php +++ b/index.php @@ -15,6 +15,7 @@ require_once __DIR__.'/vendor/silex.phar'; $app = new Silex\Application(); $app['baseurl'] = $config['app']['baseurl']; +$app['filetypes'] = $config['filetypes']; // Register Git and Twig libraries $app['autoloader']->registerNamespace('Git', __DIR__.'/lib'); diff --git a/lib/Application/Utils.php b/lib/Application/Utils.php index f844e6d..78767a6 100644 --- a/lib/Application/Utils.php +++ b/lib/Application/Utils.php @@ -2,11 +2,20 @@ namespace Application; +use Silex\Application; + /** * General helper class, mostly used for string parsing inside the application controllers */ class Utils { + protected $app; + + public function __construct(Application $app) + { + $this->app = $app; + } + /** * Builds a breadcrumb array based on a path spec * @@ -209,8 +218,14 @@ class Utils return 'image'; case 'bmp': return 'image'; - default: - return 'text'; + } + + if (!empty($this->app['filetypes'])) { + foreach ($this->app['filetypes'] as $ext => $type) { + if ($fileType == $ext) { + return $type; + } + } } } diff --git a/lib/Application/UtilsServiceProvider.php b/lib/Application/UtilsServiceProvider.php index 2be4370..20d5367 100644 --- a/lib/Application/UtilsServiceProvider.php +++ b/lib/Application/UtilsServiceProvider.php @@ -16,7 +16,7 @@ class UtilsServiceProvider implements ServiceProviderInterface public function register(Application $app) { $app['utils'] = function () use ($app) { - return new Utils; + return new Utils($app); }; } } \ No newline at end of file