Skip to content

Commit

Permalink
add service and componentlist output (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored Jul 11, 2017
1 parent 064ac20 commit c9aaea1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/ComponentTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']]),
];
}

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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}
*/
Expand Down

0 comments on commit c9aaea1

Please sign in to comment.