Skip to content

Commit ccf6386

Browse files
committed
add type hint in documentation
1 parent 7cea86e commit ccf6386

12 files changed

Lines changed: 2232 additions & 2 deletions

docs/en/dbal-type.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ To register a custom DBAL type, create a class that extends
2424
return $platform->getDecimalTypeDeclarationSQL($column);
2525
}
2626
27-
public function convertToPHPValue($value, AbstractPlatform $platform): mixed
27+
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed
2828
{
2929
return $value;
3030
}
3131
32-
public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed
32+
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed
3333
{
3434
return $value;
3535
}

docs/output/configuration.html

Lines changed: 1028 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Custom ID Generators</title>
5+
6+
</head>
7+
<body>
8+
<!-- content start -->
9+
<div class="section" id="custom-id-generators">
10+
<h1>Custom ID Generators</h1>
11+
12+
<p>Custom ID generators are classes that allow implementing custom logic to generate
13+
identifiers for your entities. They extend <code>Doctrine\ORM\Id\AbstractIdGenerator</code>
14+
and implement the custom logic in the <code>generate(EntityManager $em, $entity)</code>
15+
method. Before Doctrine bundle 2.3, custom ID generators were always created
16+
without any constructor arguments.</p>
17+
18+
19+
<p>Starting with Doctrine bundle 2.3, the <code>CustomIdGenerator</code> attribute can be
20+
used to reference any services tagged with the <code>doctrine.id_generator</code> tag.
21+
If you enable autoconfiguration (which is the default most of the time), Symfony
22+
will add this tag for you automatically if you implement your own id-generators.</p>
23+
24+
25+
<p>When using Symfony&#039;s Doctrine bridge and Uid component 5.3 or higher, two services
26+
are provided: <code>doctrine.ulid_generator</code> to generate ULIDs, and
27+
<code>doctrine.uuid_generator</code> to generate UUIDs.</p>
28+
29+
<pre><code class="language-php">&lt;?php
30+
// User.php
31+
32+
use Doctrine\ORM\Mapping as ORM;
33+
34+
#[ORM\Entity]
35+
class User
36+
{
37+
#[ORM\Id]
38+
#[ORM\Column(type: &#039;uuid&#039;)]
39+
#[ORM\GeneratedValue(strategy: &#039;CUSTOM&#039;)]
40+
#[ORM\CustomIdGenerator(&#039;doctrine.uuid_generator&#039;)]
41+
private $id;
42+
43+
// ....
44+
}</code></pre>
45+
46+
47+
<p>See also
48+
<a href="https://www.doctrine-project.org/projects/doctrine-orm/en/3.3/reference/attributes-reference.html#attrref_customidgenerator">https://www.doctrine-project.org/projects/doctrine-orm/en/3.3/reference/attributes-reference.html#attrref_customidgenerator</a>
49+
for more info about custom ID generators.</p>
50+
51+
</div>
52+
<!-- content end -->
53+
</body>
54+
</html>

docs/output/dbal-type.html

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>DBAL Types</title>
5+
6+
</head>
7+
<body>
8+
<!-- content start -->
9+
<div class="section" id="dbal-types">
10+
<h1>DBAL Types</h1>
11+
12+
<p>Custom DBAL types can be registered using the <code>AsDbalType</code> attribute. This
13+
attribute allows you to define a name for your custom type directly in the class
14+
definition.</p>
15+
16+
17+
<p>To register a custom DBAL type, create a class that extends
18+
<code>Doctrine\DBAL\Types\Type</code> and add the <code>#[AsDbalType]</code> attribute to it:</p>
19+
20+
<pre><code class="language-php">namespace App\Doctrine\Type;
21+
22+
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDbalType;
23+
use Doctrine\DBAL\Platforms\AbstractPlatform;
24+
use Doctrine\DBAL\Types\Type;
25+
26+
#[AsDbalType(name: &#039;money&#039;)]
27+
class MoneyType extends Type
28+
{
29+
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
30+
{
31+
return $platform-&gt;getDecimalTypeDeclarationSQL($column);
32+
}
33+
34+
public function convertToPHPValue($value, AbstractPlatform $platform): mixed
35+
{
36+
return $value;
37+
}
38+
39+
public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed
40+
{
41+
return $value;
42+
}
43+
44+
public function getName(): string
45+
{
46+
return &#039;money&#039;;
47+
}
48+
}</code></pre>
49+
50+
51+
<p>When using the <code>AsDbalType</code> attribute, the type will be automatically
52+
registered with Doctrine.</p>
53+
54+
<div class="section" id="manual-registration">
55+
<h2>Manual Registration</h2>
56+
57+
<p>Alternatively, you can register custom types in your configuration:</p>
58+
59+
<div class="configuration-block">
60+
<div role="tablist" aria-label="Configuration formats" class="configuration-tabs configuration-tabs-length-3">
61+
<button role="tab" type="button" data-language="yaml"
62+
aria-controls="configuration-block-tabpanel-ed4c121d12c6faa5ca20c5005d6db39d" aria-selected="true"
63+
data-active="true" >
64+
<span>Yaml</span>
65+
</button>
66+
<button role="tab" type="button" data-language="xml"
67+
aria-controls="configuration-block-tabpanel-bc5c95441c428999b3e0c4b4ffa7e792" aria-selected="false"
68+
tabindex="-1">
69+
<span>Xml</span>
70+
</button>
71+
<button role="tab" type="button" data-language="php"
72+
aria-controls="configuration-block-tabpanel-4efc08d5822955550c68ac6019d85274" aria-selected="false"
73+
tabindex="-1">
74+
<span>Php</span>
75+
</button>
76+
</div>
77+
78+
<div role="tabpanel" id="configuration-block-tabpanel-ed4c121d12c6faa5ca20c5005d6db39d" aria-label="Yaml" class="configuration-codeblock" data-language="yaml" style="">
79+
<pre><code class="language-yaml"># config/packages/doctrine.yaml
80+
doctrine:
81+
dbal:
82+
types:
83+
money: App\Doctrine\Type\MoneyType</code></pre>
84+
85+
</div>
86+
<div role="tabpanel" id="configuration-block-tabpanel-bc5c95441c428999b3e0c4b4ffa7e792" aria-label="Xml" class="configuration-codeblock" data-language="xml" style="display: none">
87+
<pre><code class="language-xml">&lt;!-- config/packages/doctrine.xml --&gt;
88+
&lt;container xmlns=&quot;http://symfony.com/schema/dic/services&quot;
89+
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
90+
xmlns:doctrine=&quot;http://symfony.com/schema/dic/doctrine&quot;
91+
xsi:schemaLocation=&quot;http://symfony.com/schema/dic/services
92+
http://symfony.com/schema/dic/services/services-1.0.xsd
93+
http://symfony.com/schema/dic/doctrine
94+
http://symfony.com/schema/dic/doctrine/doctrine-1.0.xsd&quot;&gt;
95+
96+
&lt;doctrine:config&gt;
97+
&lt;doctrine:dbal&gt;
98+
&lt;doctrine:type name=&quot;money&quot;&gt;App\Doctrine\Type\MoneyType&lt;/doctrine:type&gt;
99+
&lt;/doctrine:dbal&gt;
100+
&lt;/doctrine:config&gt;
101+
&lt;/container&gt;</code></pre>
102+
103+
</div>
104+
<div role="tabpanel" id="configuration-block-tabpanel-4efc08d5822955550c68ac6019d85274" aria-label="Php" class="configuration-codeblock" data-language="php" style="display: none">
105+
<pre><code class="language-php">// config/packages/doctrine.php
106+
use App\Doctrine\Type\MoneyType;
107+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
108+
109+
return static function (ContainerConfigurator $containerConfigurator): void {
110+
$containerConfigurator-&gt;extension(&#039;doctrine&#039;, [
111+
&#039;dbal&#039; =&gt; [
112+
&#039;types&#039; =&gt; [
113+
&#039;money&#039; =&gt; MoneyType::class,
114+
],
115+
],
116+
]);
117+
};</code></pre>
118+
119+
</div>
120+
</div>
121+
</div>
122+
</div>
123+
<!-- content end -->
124+
</body>
125+
</html>

docs/output/doctrine-console.html

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Doctrine Console</title>
5+
6+
</head>
7+
<body>
8+
<!-- content start -->
9+
<div class="section" id="doctrine-console">
10+
<h1>Doctrine Console</h1>
11+
12+
<p>Some Doctrine packages such as <code>doctrine/dbal</code> and <code>doctrine/orm</code>
13+
provide useful console commands to interact with your database and your
14+
entities:</p>
15+
16+
17+
18+
<ul>
19+
<li class="dash"><a href="https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/cli-tools.html#cli-tools">Doctrine DBAL Commands</a></li>
20+
<li class="dash"><a href="https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/tools.html#doctrine-console">Doctrine ORM Commands</a></li>
21+
</ul>
22+
23+
24+
<p>This bundle automatically registers those commands, but it renames them
25+
in the process so as to group them under the <code>doctrine:</code> namespace.</p>
26+
27+
28+
<p>Note that the bundle also provide some additional commands that are not
29+
part of the aforementioned packages.</p>
30+
31+
<div class="section" id="command-name-mapping">
32+
<h2>Command Name Mapping</h2>
33+
34+
<p>The following table shows the mapping between the original Doctrine command
35+
names and the names used by this bundle:</p>
36+
37+
<table>
38+
<thead>
39+
<tr>
40+
<th>Bundle Command Name</th>
41+
<th>Original Doctrine Command Name</th>
42+
</tr>
43+
</thead>
44+
<tbody>
45+
<tr>
46+
<td><code>doctrine:cache:clear-metadata</code></td>
47+
<td><code>orm:clear-cache:metadata</code></td>
48+
</tr>
49+
<tr>
50+
<td><code>doctrine:cache:clear-query</code></td>
51+
<td><code>orm:clear-cache:query</code></td>
52+
</tr>
53+
<tr>
54+
<td><code>doctrine:cache:clear-result</code></td>
55+
<td><code>orm:clear-cache:result</code></td>
56+
</tr>
57+
<tr>
58+
<td><code>doctrine:cache:clear-collection-region</code></td>
59+
<td><code>orm:clear-cache:region:collection</code></td>
60+
</tr>
61+
<tr>
62+
<td><code>doctrine:cache:clear-entity-region</code></td>
63+
<td><code>orm:clear-cache:region:entity</code></td>
64+
</tr>
65+
<tr>
66+
<td><code>doctrine:cache:clear-query-region</code></td>
67+
<td><code>orm:clear-cache:region:query</code></td>
68+
</tr>
69+
<tr>
70+
<td><code>doctrine:schema:create</code></td>
71+
<td><code>orm:schema-tool:create</code></td>
72+
</tr>
73+
<tr>
74+
<td><code>doctrine:schema:drop</code></td>
75+
<td><code>orm:schema-tool:drop</code></td>
76+
</tr>
77+
<tr>
78+
<td><code>doctrine:schema:update</code></td>
79+
<td><code>orm:schema-tool:update</code></td>
80+
</tr>
81+
<tr>
82+
<td><code>doctrine:mapping:info</code></td>
83+
<td><code>orm:info</code></td>
84+
</tr>
85+
<tr>
86+
<td><code>doctrine:mapping:describe</code></td>
87+
<td><code>orm:mapping:describe</code></td>
88+
</tr>
89+
<tr>
90+
<td><code>doctrine:query:dql</code></td>
91+
<td><code>orm:run-dql</code></td>
92+
</tr>
93+
<tr>
94+
<td><code>doctrine:schema:validate</code></td>
95+
<td><code>orm:validate-schema</code></td>
96+
</tr>
97+
</tbody>
98+
</table>
99+
100+
<p>Additionally, the bundle provides the following commands:</p>
101+
102+
103+
104+
<ul>
105+
<li class="dash"><code>doctrine:database:create</code></li>
106+
<li class="dash"><code>doctrine:database:drop</code></li>
107+
</ul>
108+
109+
110+
<p>To get a list of all available Doctrine commands, run:</p>
111+
112+
<pre><code class="language-console">php bin/console list doctrine</code></pre>
113+
114+
115+
<p>It is possible to get help on any specific command. For example,
116+
to get help on the <code>doctrine:schema:update</code> command, run:</p>
117+
118+
<pre><code class="language-console">php bin/console doctrine:schema:update --help</code></pre>
119+
120+
</div>
121+
</div>
122+
<!-- content end -->
123+
</body>
124+
</html>

0 commit comments

Comments
 (0)