diff --git a/.editorconfig b/.editorconfig index 31ed3d9..aa06f70 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,3 @@ end_of_line = lf insert_final_newline = true indent_style = space indent_size = 4 - -[*.json] -indent_size = 2 diff --git a/Controller/StaticController.php b/Controller/StaticController.php index 38a9f9e..6c34a62 100755 --- a/Controller/StaticController.php +++ b/Controller/StaticController.php @@ -9,9 +9,8 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Twig_Error; - -class StaticController extends Controller { - +class StaticController extends Controller +{ // The excution flow can go e.g.: findAction -> renderTwig -> showTwigError, // and we'd like to keep some information around. /** @var bool The kernel.debug parameter */ @@ -32,7 +31,8 @@ class StaticController extends Controller { /** * List Assetic bundles */ - public function rootAction() { + public function rootAction() + { return $this->render('@GradientzTwigExpress/root.html.twig', [ 'bundles' => $this->getParameter('twig_express.bundles') ]); @@ -45,7 +45,8 @@ public function rootAction() { * @return RedirectResponse|Response * @throws \Exception */ - public function findAction($slug, $path) { + public function findAction($slug, $path) + { $this->debug = $this->getParameter('kernel.debug'); $cleanPath = Utils::getCleanPath($path); $pathExt = pathinfo($cleanPath, PATHINFO_EXTENSION); @@ -124,7 +125,8 @@ public function findAction($slug, $path) { * @param string $urlFragment URL without base or bundle key * @return Response */ - private function renderDir($dirPath, $urlFragment) { + private function renderDir($dirPath, $urlFragment) + { // Prepare breadcrumbs $breadcrumbs = Utils::makeBreadcrumbs( $this->baseUrl, @@ -156,7 +158,8 @@ private function renderDir($dirPath, $urlFragment) { * @param string $urlFragment URL without base or bundle key * @return Response */ - private function render404($urlFragment) { + private function render404($urlFragment) + { // Prepare breadcrumbs $breadcrumbs = Utils::makeBreadcrumbs( $this->baseUrl, @@ -190,7 +193,8 @@ private function render404($urlFragment) { * @return Response * @throws Twig_Error */ - private function renderTwig($templateName) { + private function renderTwig($templateName) + { // Do we have an extension, like .html or .json? $ext = pathinfo(substr($templateName, 0, -5), PATHINFO_EXTENSION); $cType = $ext ? Utils::getMediaType($ext) . ';charset=utf-8' : null; @@ -214,7 +218,8 @@ private function renderTwig($templateName) { * @param string $templateName Path of rendered template (error may be in a different template) * @return Response */ - private function showTwigError(Twig_Error $error, $templateName) { + private function showTwigError(Twig_Error $error, $templateName) + { $line = $error->getTemplateLine(); $message = $error->getRawMessage(); @@ -278,7 +283,8 @@ private function showTwigError(Twig_Error $error, $templateName) { * @param string $urlFragment URL without base or bundle key * @return Response */ - private function showSource($systemPath, $urlFragment) { + private function showSource($systemPath, $urlFragment) + { // Prepare breadcrumbs $breadcrumbs = Utils::makeBreadcrumbs( $this->baseUrl, @@ -294,5 +300,4 @@ private function showSource($systemPath, $urlFragment) { ]; return $this->render('@GradientzTwigExpress/page.html.twig', $data); } - } diff --git a/Core/Utils.php b/Core/Utils.php index e96483c..1ebc7d2 100644 --- a/Core/Utils.php +++ b/Core/Utils.php @@ -5,16 +5,16 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\DependencyInjection\ContainerInterface; - -class Utils { - +class Utils +{ /** * Cleans up a local resource path, removing back-slashes, double dots, etc. * Should not be necessary for content from a URL but let's be on the safe side. * @param string $path * @return string */ - static function getCleanPath($path) { + static function getCleanPath($path) + { return preg_replace( ['/\\\/', '/\/{2,}/', '/\.{2,}/'], ['/', '/', '.'], @@ -28,7 +28,8 @@ static function getCleanPath($path) { * @param string $ext - lowercase file extension * @return string The corresponding media type */ - static function getMediaType($ext) { + static function getMediaType($ext) + { $type = 'text/plain'; $knownTypes = [ 'htm' => 'text/html', @@ -53,13 +54,14 @@ static function getMediaType($ext) { * @param string $path * @return array */ - static function makeBreadcrumbs($baseUrl, $bundleName, $path) { + static function makeBreadcrumbs($baseUrl, $bundleName, $path) + { $url = $baseUrl . '/'; $crumbs = [['url' => $url, 'name' => $bundleName]]; $fragments = array_filter(explode('/', $path)); $last = array_pop($fragments); - foreach($fragments as $fragment) { + foreach ($fragments as $fragment) { $url .= $fragment . '/'; $crumbs[] = ['url' => $url, 'name' => $fragment]; } @@ -87,7 +89,8 @@ static function makeBreadcrumbs($baseUrl, $bundleName, $path) { * @param int $extract Number of lines to show before and after an highlighted line * @return string */ - static function formatCodeBlock($code, $numbers=true, $highlight=0, $extract=4) { + static function formatCodeBlock($code, $numbers=true, $highlight=0, $extract=4) + { $escaped = htmlspecialchars($code, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); $lines = preg_split("/(\r\n|\n)/", $escaped); // Use 1-indexes @@ -122,7 +125,8 @@ static function formatCodeBlock($code, $numbers=true, $highlight=0, $extract=4) * @param string $filename * @return string */ - static function getHighlightLanguage($filename) { + static function getHighlightLanguage($filename) + { // Try to figure out the subLanguage $subLang = 'xml'; $subLangs = [ @@ -142,5 +146,4 @@ static function getHighlightLanguage($filename) { } return $subLang; } - } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 7dae413..70f9cc2 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -5,10 +5,10 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; - -class Configuration implements ConfigurationInterface { - - public function getConfigTreeBuilder() { +class Configuration implements ConfigurationInterface +{ + public function getConfigTreeBuilder() + { $treeBuilder = new TreeBuilder(); $treeBuilder->root('twig_express') ->children() @@ -37,5 +37,4 @@ public function getConfigTreeBuilder() { ->end(); return $treeBuilder; } - } diff --git a/DependencyInjection/GradientzTwigExpressExtension.php b/DependencyInjection/GradientzTwigExpressExtension.php index 6faf3fe..d3564d2 100644 --- a/DependencyInjection/GradientzTwigExpressExtension.php +++ b/DependencyInjection/GradientzTwigExpressExtension.php @@ -5,14 +5,15 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; - -class GradientzTwigExpressExtension extends Extension { - - public function getAlias() { +class GradientzTwigExpressExtension extends Extension +{ + public function getAlias() + { return 'twig_express'; } - public function load(array $configs, ContainerBuilder $container) { + public function load(array $configs, ContainerBuilder $container) + { $config = $this->processConfiguration(new Configuration(), $configs); // Make sure we have a base_url parameter so we can use it in routes @@ -23,7 +24,7 @@ public function load(array $configs, ContainerBuilder $container) { // Expose configured bundle information // (Is there a better way to get access to our config from controllers???) $bundles = []; - foreach($config['bundles'] as $item) { + foreach ($config['bundles'] as $item) { $name = $item['name']; $slug = $item['slug']; // Create slug if necessary, and clean it up @@ -39,5 +40,4 @@ public function load(array $configs, ContainerBuilder $container) { } $container->setParameter('twig_express.bundles', $bundles); } - } diff --git a/GradientzTwigExpressBundle.php b/GradientzTwigExpressBundle.php index 972fba1..87e9d67 100755 --- a/GradientzTwigExpressBundle.php +++ b/GradientzTwigExpressBundle.php @@ -4,10 +4,10 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; -class GradientzTwigExpressBundle extends Bundle { - - public function getContainerExtension() { +class GradientzTwigExpressBundle extends Bundle +{ + public function getContainerExtension() + { return new DependencyInjection\GradientzTwigExpressExtension(); } - }