Add parameter descriptors
This commit is contained in:
parent
4a06daf2c3
commit
6aa1050793
@ -114,17 +114,6 @@ abstract class Descriptor implements DescriptorInterface
|
|||||||
*/
|
*/
|
||||||
abstract protected function describeRoute(Route $route, array $options = array());
|
abstract protected function describeRoute(Route $route, array $options = array());
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes a specific container parameter.
|
|
||||||
*
|
|
||||||
* @param mixed $parameterValue
|
|
||||||
* @param array $options
|
|
||||||
*/
|
|
||||||
protected function describeContainerParameter($parameterValue, array $options = array())
|
|
||||||
{
|
|
||||||
$this->write($this->formatParameter($parameterValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes container parameters.
|
* Describes container parameters.
|
||||||
*
|
*
|
||||||
@ -179,6 +168,14 @@ abstract class Descriptor implements DescriptorInterface
|
|||||||
*/
|
*/
|
||||||
abstract protected function describeContainerAlias(Alias $alias, array $options = array());
|
abstract protected function describeContainerAlias(Alias $alias, array $options = array());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes a container parameter.
|
||||||
|
*
|
||||||
|
* @param parameter
|
||||||
|
* @param array $options
|
||||||
|
*/
|
||||||
|
abstract protected function describeContainerParameter($parameter, array $options = array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a value as string.
|
* Formats a value as string.
|
||||||
*
|
*
|
||||||
|
@ -134,6 +134,16 @@ class JsonDescriptor extends Descriptor
|
|||||||
$this->writeData($this->getContainerAliasData($alias), $options);
|
$this->writeData($this->getContainerAliasData($alias), $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function describeContainerParameter($parameter, array $options = array())
|
||||||
|
{
|
||||||
|
$key = isset($options['parameter']) ? $options['parameter'] : '';
|
||||||
|
|
||||||
|
$this->writeData(array($key => $this->formatParameter($parameter)), $options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes data as json.
|
* Writes data as json.
|
||||||
*
|
*
|
||||||
|
@ -207,6 +207,14 @@ class MarkdownDescriptor extends Descriptor
|
|||||||
$this->write(isset($options['id']) ? sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output) : $output);
|
$this->write(isset($options['id']) ? sprintf("%s\n%s\n\n%s\n", $options['id'], str_repeat('~', strlen($options['id'])), $output) : $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function describeContainerParameter($parameter, array $options = array())
|
||||||
|
{
|
||||||
|
$this->write(isset($options['parameter']) ? sprintf("%s\n%s\n\n%s", $options['parameter'], str_repeat('=', strlen($options['parameter'])), $this->formatParameter($parameter)): $parameter);
|
||||||
|
}
|
||||||
|
|
||||||
private function formatRouterConfig(array $array)
|
private function formatRouterConfig(array $array)
|
||||||
{
|
{
|
||||||
if (!count($array)) {
|
if (!count($array)) {
|
||||||
|
@ -276,6 +276,14 @@ class TextDescriptor extends Descriptor
|
|||||||
$this->writeText(sprintf('This service is an alias for the service <info>%s</info>', (string) $alias), $options);
|
$this->writeText(sprintf('This service is an alias for the service <info>%s</info>', (string) $alias), $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function describeContainerParameter($parameter, array $options = array())
|
||||||
|
{
|
||||||
|
$this->writeText($this->formatParameter($parameter), $options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $array
|
* @param array $array
|
||||||
*
|
*
|
||||||
|
@ -91,6 +91,14 @@ class XmlDescriptor extends Descriptor
|
|||||||
$this->writeDocument($this->getContainerAliasDocument($alias, isset($options['id']) ? $options['id'] : null));
|
$this->writeDocument($this->getContainerAliasDocument($alias, isset($options['id']) ? $options['id'] : null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function describeContainerParameter($parameter, array $options = array())
|
||||||
|
{
|
||||||
|
$this->writeDocument($this->getContainerParameterDocument($parameter, $options));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes DOM document.
|
* Writes DOM document.
|
||||||
*
|
*
|
||||||
@ -365,4 +373,24 @@ class XmlDescriptor extends Descriptor
|
|||||||
|
|
||||||
return $dom;
|
return $dom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $parameter
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return \DOMDocument
|
||||||
|
*/
|
||||||
|
private function getContainerParameterDocument($parameter, $options = array())
|
||||||
|
{
|
||||||
|
$dom = new \DOMDocument('1.0', 'UTF-8');
|
||||||
|
$dom->appendChild($parameterXML = $dom->createElement('parameter'));
|
||||||
|
|
||||||
|
if (isset($options['parameter'])) {
|
||||||
|
$parameterXML->setAttribute('key', $options['parameter']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$parameterXML->appendChild(new \DOMText($this->formatParameter($parameter)));
|
||||||
|
|
||||||
|
return $dom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,21 @@ abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase
|
|||||||
return $this->getDescriptionTestData(ObjectsProvider::getContainerAliases());
|
return $this->getDescriptionTestData(ObjectsProvider::getContainerAliases());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @dataProvider getDescribeContainerParameterTestData */
|
||||||
|
public function testDescribeContainerParameter($parameter, $expectedDescription, array $options)
|
||||||
|
{
|
||||||
|
$this->assertDescription($expectedDescription, $parameter, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescribeContainerParameterTestData()
|
||||||
|
{
|
||||||
|
$data = $this->getDescriptionTestData(ObjectsProvider::getContainerParameter());
|
||||||
|
|
||||||
|
array_push($data[0], array('parameter' => 'database_name'));
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
abstract protected function getDescriptor();
|
abstract protected function getDescriptor();
|
||||||
abstract protected function getFormat();
|
abstract protected function getFormat();
|
||||||
|
|
||||||
|
@ -66,6 +66,16 @@ class ObjectsProvider
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getContainerParameter()
|
||||||
|
{
|
||||||
|
$builder = new ContainerBuilder();
|
||||||
|
$builder->setParameter('database_name', 'symfony');
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'parameter' => $builder
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getContainerBuilders()
|
public static function getContainerBuilders()
|
||||||
{
|
{
|
||||||
$builder1 = new ContainerBuilder();
|
$builder1 = new ContainerBuilder();
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"database_name": "symfony"
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
database_name
|
||||||
|
=============
|
||||||
|
|
||||||
|
symfony
|
@ -0,0 +1 @@
|
|||||||
|
symfony
|
@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<parameter key="database_name">symfony</parameter>
|
Reference in New Issue
Block a user