Skip to content

Commit 91cc5b2

Browse files
authored
Merge pull request #473 from greg0ire/document-extension
Document how to create an extension
2 parents 90748cf + 0ae7b82 commit 91cc5b2

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

docs/components/compiler.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@ This library uses a simplified compiler design. This basically means that our pi
88
than a regular compiler. But its following the same semantics.
99

1010
Lexing and Parsing
11+
==================
1112

12-
A typical compiler will have separate lexing, syntax analisys. However the parser
13-
was designed to do part of the lexing because of all context dependend logic of most Markup languages.
13+
A typical compiler will have separate lexing, syntax analysis. However the parser
14+
was designed to do part of the lexing because of all context-dependent logic of most Markup languages.
1415
We call this the parsing phase. This will result into an AST that is mostly close to the original source. It
1516
might contain some optimizations for later use.
1617

1718
Semantic analysis and Intermediate code generation
19+
==================================================
1820

1921
The semantic analysis phase of this library is performing a number of steps to collect information of the parsed markup
20-
language. An good example is the collection of the table of contents and the metadata of the parsed documents.
22+
language. A good example is the collection of the table of contents and the metadata of the parsed documents.
2123
This is the moment where document node traversers are executed.
2224

2325
Code optimization
26+
=================
2427

2528
Do some pre-rendering stuff, like buiding the TOC content and other rendering preparations before the real rendering starts.
2629

2730
Code generation
31+
===============
2832

29-
Code generation a.k. rendering. We do deliver a headless
33+
Code generation a.k.a. rendering. We do deliver a headless

docs/extension/index.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
Extending the phpdocumentor/guides
55
==================================
66

7+
``phpdocumentor/guides`` relies on `Symfony Dependency Injection
8+
Container
9+
<https://symfony.com/doc/current/components/dependency_injection.html#setting-up-the-container-with-configuration-files>`__
10+
extensions. This means that to extend the guides, you need to define
11+
such an extension, after what it becomes possible to make the guides CLI
12+
aware of it by creating a ``guides.xml`` file in the directory from
13+
which you invoke the CLI.
14+
15+
It should look like this::
16+
17+
.. code-block:: xml
18+
19+
<?xml version="1.0" encoding="UTF-8" ?>
20+
<guides>
21+
<extension class="YourName\YourExtension\DependencyInjection\YourExtension"/>
22+
</guides>
23+
24+
Internally, the guides CLI defines and uses default extensions.
25+
Once you have that set up, you can create PHP classes, define services
26+
from it, and tag them so that they are recognized and usable by the
27+
guides CLI.
28+
729
Some ways to extend the guides:
830

931
.. toctree::

packages/guides-cli/src/DependencyInjection/ContainerFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ private function resolveExtensionClass(string $name): string
9797

9898
$fqcn = implode('\\', [$fqcn, 'DependencyInjection', $package . 'Extension']);
9999
if (!class_exists($fqcn)) {
100-
throw new LogicException(sprintf('Extension "%s" does not exists.', $fqcn));
100+
throw new LogicException(sprintf('Extension "%s" does not exist.', $fqcn));
101101
}
102102
}
103103

104104
if (!is_a($fqcn, ExtensionInterface::class, true)) {
105-
throw new LogicException(sprintf('Extension "%s" does not exists.', $fqcn));
105+
throw new LogicException(sprintf('Extension "%s" does not exist.', $fqcn));
106106
}
107107

108108
return $fqcn;

packages/guides-restructured-text/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This repository is part of `phpDocumentor's Guides library <https://github.com/p
2323
designed to take hand-written documentation in code repositories and create an AST (abstract syntax tree) from it.
2424
This AST is then fed to a renderer, which produces the desired output, such as HTML.
2525

26-
The package `phpdocumentor/guides-markdown <https://packagist.org/packages/phpdocumentor/guides-restructured-text>`__ adds
26+
The package `phpdocumentor/guides-restructured-text <https://packagist.org/packages/phpdocumentor/guides-restructured-text>`__ adds
2727
`reStructuredText Markup <https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html>`__ support to the
2828
phpDocumentor's Guides library.
2929

0 commit comments

Comments
 (0)