From c9aaea1eda26d1a59cf638f23523a76344beb1e2 Mon Sep 17 00:00:00 2001 From: L91 Date: Tue, 11 Jul 2017 13:32:27 +0200 Subject: [PATCH] add service and componentlist output (#1) --- src/ComponentTwigExtension.php | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/ComponentTwigExtension.php b/src/ComponentTwigExtension.php index c32f720..05c3c4f 100644 --- a/src/ComponentTwigExtension.php +++ b/src/ComponentTwigExtension.php @@ -30,8 +30,10 @@ public function getFunctions() return [ new \Twig_SimpleFunction('register_component', [$this, 'registerComponent']), new \Twig_SimpleFunction('get_components', [$this, 'getComponents'], ['is_safe' => ['html']]), + new \Twig_SimpleFunction('get_component_list', [$this, 'getComponentList'], ['is_safe' => ['html']]), new \Twig_SimpleFunction('call_service', [$this, 'callService']), new \Twig_SimpleFunction('get_services', [$this, 'getServices'], ['is_safe' => ['html']]), + new \Twig_SimpleFunction('get_service_list', [$this, 'getServiceList'], ['is_safe' => ['html']]), ]; } @@ -93,6 +95,27 @@ public function getComponents($jsonEncode = true, $clear = true) return $jsonEncode ? json_encode($components) : $components; } + /** + * Get component list. + * + * @param bool $jsonEncode + * + * @return string. + */ + public function getComponentList($jsonEncode = false) + { + $components = []; + + foreach ($this->components as $component) { + $name = $component['name']; + $components[$name] = $name; + } + + $components = array_values($components); + + return $jsonEncode ? json_encode($components) : $components; + } + /** * Call a service function. * @@ -128,6 +151,27 @@ public function getServices($jsonEncode = true, $clear = true) return $jsonEncode ? json_encode($services) : $services; } + /** + * Get service list. + * + * @param bool $jsonEncode + * + * @return string. + */ + public function getServiceList($jsonEncode = false) + { + $services = []; + + foreach ($this->services as $service) { + $name = $service['name']; + $services[$name] = $name; + } + + $services = array_values($services); + + return $jsonEncode ? json_encode($services) : $services; + } + /** * {@inheritdoc} */