Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Config] [WIP] Add doc links support in Config component #21081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected function configure()
new InputArgument('name', InputArgument::OPTIONAL, 'The Bundle name or the extension alias'),
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (yaml or xml)', 'yaml'),
new InputOption('with-doc', null, InputOption::VALUE_NONE, 'Show documentation link'),
))
->setDescription('Dumps the default configuration for an extension')
->setHelp(<<<'EOF'
Expand All @@ -60,6 +61,10 @@ protected function configure()

<info>php %command.full_name% framework profiler.matcher</info>

The <info>--with-doc</info> option dumps nodes with documentation URL.

<info>php %command.full_name% FrameworkBundle --with-doc</info>

EOF
)
;
Expand Down Expand Up @@ -110,14 +115,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
$message .= sprintf(' at path "%s"', $path);
}

$withDoc = $input->getOption('with-doc');
switch ($format) {
case 'yaml':
$io->writeln(sprintf('# %s', $message));
$dumper = new YamlReferenceDumper();
$dumper = new YamlReferenceDumper($withDoc);
break;
case 'xml':
$io->writeln(sprintf('<!-- %s -->', $message));
$dumper = new XmlReferenceDumper();
$dumper = new XmlReferenceDumper($withDoc);
break;
default:
$io->writeln($message);
Expand Down
254 changes: 205 additions & 49 deletions 254 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions 20 src/Symfony/Component/Config/Definition/BaseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,26 @@ public function getPath()
return $path;
}

/**
* Sets an documentation URL.
*
* @param string $doc The documentation URL
*/
public function setDoc($doc)
{
$this->setAttribute('doc', $doc);
}

/**
* Retrieves the documentation URL configuration for this node.
*
* @return string The documentation URL
*/
public function getDoc()
{
return $this->getAttribute('doc');
}

/**
* Merges two values together.
*
Expand Down
22 changes: 22 additions & 0 deletions 22 src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Config\Definition\NodeInterface;
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
use Symfony\Component\HttpKernel\Kernel;

/**
* This class provides a fluent interface for defining a node.
Expand Down Expand Up @@ -340,4 +341,25 @@ protected function normalization()
* @throws InvalidDefinitionException When the definition is invalid
*/
abstract protected function createNode();

/**
* Sets doc configuration.
*
* @param string $doc
*
* @return NodeDefinition|$this
*/
public function doc($doc)
{
if (false === filter_var($doc, FILTER_VALIDATE_URL)) {
throw new \InvalidArgumentException(sprintf('The "%s" is not a valid documentation URL.', $doc));
}

// Adds sf version
if (false !== strpos($doc, 'https://symfony.com/doc/')) {
$doc = sprintf($doc, Kernel::MAJOR_VERSION.'.'.Kernel::MINOR_VERSION);
}

return $this->attribute('doc', $doc);
}
}
32 changes: 32 additions & 0 deletions 32 src/Symfony/Component/Config/Definition/Dumper/ReferenceDumper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Config\Definition\Dumper;

use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* Dumps a reference configuration for the given configuration/node instance.
*
* @author Dany Maillard <danymaillard93b@gmail.com>
*/
abstract class ReferenceDumper
{
protected $reference;
protected $withDoc;

public function __construct($withDoc = false)
{
$this->withDoc = $withDoc;
}

abstract public function dump(ConfigurationInterface $configuration, $namespace = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
*
* @author Wouter J <waldio.webdesign@gmail.com>
*/
class XmlReferenceDumper
class XmlReferenceDumper extends ReferenceDumper
{
private $reference;

public function dump(ConfigurationInterface $configuration, $namespace = null)
{
return $this->dumpNode($configuration->getConfigTreeBuilder()->buildTree(), $namespace);
Expand Down Expand Up @@ -149,6 +147,11 @@ private function writeNode(NodeInterface $node, $depth = 0, $root = false, $name
$comments[] = 'Example: '.$example;
}

// doc
if ($this->withDoc && $doc = $child->getDoc()) {
$comments[] = 'Doc: '.$doc;
}

if ($child->isRequired()) {
$comments[] = 'Required';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
*
* @author Kevin Bond <kevinbond@gmail.com>
*/
class YamlReferenceDumper
class YamlReferenceDumper extends ReferenceDumper
{
private $reference;

public function dump(ConfigurationInterface $configuration)
public function dump(ConfigurationInterface $configuration, $namespace = null)
{
return $this->dumpNode($configuration->getConfigTreeBuilder()->buildTree());
}
Expand Down Expand Up @@ -128,6 +126,11 @@ private function writeNode(NodeInterface $node, $depth = 0, $prototypedArray = f
$comments[] = 'Example: '.$example;
}

// doc
if ($this->withDoc && $doc = $node->getDoc()) {
$comments[] = 'Doc: '.$doc;
}

$default = (string) $default != '' ? ' '.$default : '';
$comments = count($comments) ? '# '.implode(', ', $comments) : '';

Expand Down
7 changes: 7 additions & 0 deletions 7 src/Symfony/Component/Config/Definition/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public function hasDefaultValue();
*/
public function getDefaultValue();

/**
* Returns the documentation URL of the node.
*
* @return string The documentation URL
*/
public function getDoc();

/**
* Normalizes the supplied value.
*
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.