Skip to content

Commit fe19252

Browse files
committed
Removing basePath, cleaning up config and adding deprecated directive
1 parent bf55411 commit fe19252

File tree

10 files changed

+50
-150
lines changed

10 files changed

+50
-150
lines changed

bin/console

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ use SymfonyDocsBuilder\Application;
1919
$input = new ArgvInput();
2020
$version = $input->getParameterOption(['--symfony-version'], false === getenv('SYMFONY_VERSION') ? 'master' : getenv('SYMFONY_VERSION'));
2121

22+
if (!$version) {
23+
throw new \Exception('Please pass a --symfony-version= flag or set a SYMFONY_VERSION environment variable to 4.0, master, etc.');
24+
}
25+
2226
$application = new Application($version);
2327
$application->run($input);

conf.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Application.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ public function __construct(string $symfonyVersion)
1717
{
1818
$this->application = new BaseApplication();
1919

20-
$configuration = $this->getSymfonyDocConfiguration($basePath = getcwd());
20+
$configuration = [
21+
'symfony_api_url' => "https://api.symfony.com/%s",
22+
'php_doc_url' => "https://secure.php.net/manual/en",
23+
'symfony_doc_url' => "https://symfony.com/doc/%s",
24+
];
2125
$this->buildContext = new BuildContext(
22-
$basePath,
2326
$symfonyVersion,
2427
sprintf($configuration['symfony_api_url'], $symfonyVersion),
2528
$configuration['php_doc_url'],
@@ -38,13 +41,7 @@ public function run(InputInterface $input): int
3841
);
3942
$this->application->getDefinition()->addOption($inputOption);
4043
$this->application->add(new BuildDocsCommand($this->buildContext));
41-
$this->application->add(new CheckUrlsCommand($this->buildContext));
4244

4345
return $this->application->run($input);
4446
}
45-
46-
private function getSymfonyDocConfiguration(string $basePath): array
47-
{
48-
return json_decode(file_get_contents(sprintf('%s/conf.json', $basePath)), true);
49-
}
5047
}

src/BuildContext.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
class BuildContext
66
{
7-
private $basePath;
87
private $symfonyVersion;
98
private $symfonyApiUrl;
109
private $phpDocUrl;
@@ -17,13 +16,11 @@ class BuildContext
1716
private $disableCache = false;
1817

1918
public function __construct(
20-
string $basePath,
2119
string $symfonyVersion,
2220
string $symfonyApiUrl,
2321
string $phpDocUrl,
2422
string $symfonyDocUrl
2523
) {
26-
$this->basePath = $basePath;
2724
$this->symfonyVersion = $symfonyVersion;
2825
$this->symfonyApiUrl = $symfonyApiUrl;
2926
$this->phpDocUrl = $phpDocUrl;
@@ -39,11 +36,6 @@ public function initializeRuntimeConfig(string $sourceDir, string $outputDir, ?s
3936
$this->runtimeInitialized = true;
4037
}
4138

42-
public function getBasePath(): string
43-
{
44-
return $this->basePath;
45-
}
46-
4739
public function getSymfonyVersion(): string
4840
{
4941
return $this->symfonyVersion;
@@ -92,6 +84,11 @@ public function getDisableCache(): bool
9284
return $this->disableCache;
9385
}
9486

87+
public function getCacheDir(): string
88+
{
89+
return $this->getSourceDir().'/.cache';
90+
}
91+
9592
private function checkThatRuntimeConfigIsInitialized()
9693
{
9794
if (false === $this->runtimeInitialized) {

src/Command/CheckUrlsCommand.php

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/Directive/DeprecatedDirective.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace SymfonyDocsBuilder\Directive;
4+
5+
use Doctrine\RST\Directives\SubDirective;
6+
use Doctrine\RST\Nodes\Node;
7+
use Doctrine\RST\Parser;
8+
9+
class DeprecatedDirective extends SubDirective
10+
{
11+
public function getName(): string
12+
{
13+
return 'deprecated';
14+
}
15+
16+
public function processSub(Parser $parser, ?Node $document, string $variable, string $data, array $options): ?Node
17+
{
18+
$wrapperDiv = $parser->renderTemplate(
19+
'directives/deprecated.html.twig',
20+
[
21+
'version' => $data,
22+
]
23+
);
24+
25+
return $parser->getNodeFactory()->createWrapperNode($document, $wrapperDiv, '</div></div>');
26+
}
27+
}

src/KernelFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ final class KernelFactory
1616
public static function createKernel(BuildContext $buildContext, ?UrlChecker $urlChecker = null): Kernel
1717
{
1818
$configuration = new RSTParserConfiguration();
19-
$configuration->setCustomTemplateDirs([sprintf('%s/src/Templates', $buildContext->getBasePath())]);
20-
$configuration->setCacheDir(sprintf('%s/var/cache', $buildContext->getBasePath()));
19+
$configuration->setCustomTemplateDirs([__DIR__.'/Templates']);
20+
$configuration->setCacheDir(sprintf('%s/var/cache', $buildContext->getCacheDir()));
2121
$configuration->abortOnError(false);
2222

2323
if ($buildContext->getDisableCache()) {
@@ -55,6 +55,7 @@ private static function getDirectives(): array
5555
new SymfonyDirectives\CautionDirective(),
5656
new SymfonyDirectives\CodeBlockDirective(),
5757
new SymfonyDirectives\ConfigurationBlockDirective(),
58+
new SymfonyDirectives\DeprecatedDirective(),
5859
new SymfonyDirectives\IndexDirective(),
5960
new SymfonyDirectives\RoleDirective(),
6061
new SymfonyDirectives\NoteDirective(),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="deprecated"><div><span class="versionmodified">Deprecated since version {{ version }}: </span>

tests/Command/BuildDocsCommandTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BuildDocsCommandTest extends TestCase
1515
public function testBuildDocsFoo()
1616
{
1717
$buildContext = $this->createBuildContext();
18-
$outputDir = sprintf('%s/tests/_output', $buildContext->getBasePath());
18+
$outputDir = __DIR__.'/../_output';
1919

2020
$filesystem = new Filesystem();
2121
$filesystem->remove($outputDir);
@@ -24,7 +24,7 @@ public function testBuildDocsFoo()
2424
$output = $this->executeCommand(
2525
$buildContext,
2626
[
27-
'source-dir' => sprintf('%s/tests/fixtures/source/main', $buildContext->getBasePath()),
27+
'source-dir' => __DIR__.'/../tests/fixtures/source/main',
2828
'output-dir' => $outputDir,
2929
]
3030
);
@@ -36,7 +36,7 @@ public function testBuildDocsFoo()
3636
$output = $this->executeCommand(
3737
$buildContext,
3838
[
39-
'source-dir' => sprintf('%s/tests/fixtures/source/main', $buildContext->getBasePath()),
39+
'source-dir' => __DIR__.'/../tests/fixtures/source/main',
4040
'output-dir' => $outputDir,
4141
]
4242
);
@@ -46,7 +46,7 @@ public function testBuildDocsFoo()
4646
public function testBuildDocsForPdf()
4747
{
4848
$buildContext = $this->createBuildContext();
49-
$outputDir = sprintf('%s/tests/_output', $buildContext->getBasePath());
49+
$outputDir = __DIR__.'/../_output';
5050

5151
$fs = new Filesystem();
5252
if ($fs->exists($outputDir)) {
@@ -56,7 +56,7 @@ public function testBuildDocsForPdf()
5656
$output = $this->executeCommand(
5757
$buildContext,
5858
[
59-
'source-dir' => sprintf('%s/tests/fixtures/source/build-pdf', $buildContext->getBasePath()),
59+
'source-dir' => __DIR__.'/../fixtures/source/build-pdf',
6060
'output-dir' => $outputDir,
6161
'--parse-sub-path' => 'book',
6262
]
@@ -93,7 +93,6 @@ private function executeCommand(BuildContext $buildContext, array $input): strin
9393
private function createBuildContext(): BuildContext
9494
{
9595
$buildContext = new BuildContext(
96-
realpath(__DIR__.'/../..'),
9796
'4.0',
9897
'https://api.symfony.com/4.0',
9998
'https://secure.php.net/manual/en',

tests/Command/CheckUrlsCommandTest.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)