Skip to content

Commit 20371ba

Browse files
authored
Add README and agent documentation (#34)
Document the project description, installation, and usage of the maker commands with concrete examples. Add AGENTS.md with common development commands for agents working on the project, referenced from CLAUDE.md.
1 parent 19a6b47 commit 20371ba

3 files changed

Lines changed: 152 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## Development Workflow
2+
3+
1. Install dependencies: `composer install`
4+
2. Make code changes
5+
3. Auto-fix style: `php vendor/bin/phpcbf`
6+
4. Verify style: `php vendor/bin/phpcs`
7+
5. Run static analysis: `php vendor/bin/phpstan`
8+
6. Run tests: `php vendor/bin/phpunit`
9+
7. Commit changes with clear, imperative message
10+
8. Push and create pull request
11+
12+
## Key Requirements
13+
14+
- PHP 8.4+
15+
- All code must pass `phpcs` (Doctrine Coding Standard)
16+
- All tests must pass before committing
17+
- Static analysis must pass
18+
- No missing newlines at end of files
19+
- No em dashes in text

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@AGENTS.md

README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Doctrine MongoDB MakerBundle
2+
3+
A Symfony MakerBundle extension to generate MongoDB ODM code.
4+
5+
## Description
6+
7+
The MongoDB MakerBundle extends Symfony's MakerBundle to provide code generators tailored for MongoDB Object Document Mapper (ODM). It streamlines the process of creating MongoDB documents, repositories, and fixtures within your Symfony application.
8+
9+
This bundle integrates seamlessly with:
10+
- Symfony 7.4+
11+
- Doctrine MongoDB ODM 5.5+
12+
- MongoDB PHP Driver 2.1+
13+
14+
## Installation
15+
16+
Install the bundle via Composer:
17+
18+
```bash
19+
composer require doctrine/mongodb-maker-bundle
20+
```
21+
22+
Then, register the bundle in your `config/bundles.php`:
23+
24+
```php
25+
return [
26+
// ...
27+
Doctrine\Bundle\MongoDBMakerBundle\MongoDBMakerBundle::class => ['all' => true],
28+
];
29+
```
30+
31+
## Usage
32+
33+
Once installed, the bundle provides Maker commands to generate MongoDB-specific code.
34+
35+
### Available Commands
36+
37+
Run `php bin/console list make` to see all available makers:
38+
39+
```bash
40+
php bin/console list make
41+
```
42+
43+
The MongoDB MakerBundle provides the following commands:
44+
- `make:document`: create or update a MongoDB ODM document class
45+
- `make:document:index`: add an index (regular, unique, or search) to a document
46+
47+
### Examples
48+
49+
#### Create a MongoDB Document
50+
51+
Generate a new MongoDB document with properties:
52+
53+
```bash
54+
php bin/console make:document
55+
```
56+
57+
Follow the interactive prompts. Example output:
58+
59+
```
60+
Class name of the document to create or update (e.g. GoodUser):
61+
> Product
62+
63+
New property name (press <return> to stop adding fields):
64+
> name
65+
Field type (enter ? to see all types) [string]:
66+
> string
67+
Can this field be null in the database (nullable) (yes/no) [no]:
68+
> no
69+
70+
Add another property? Enter the property name (or press <return> to stop adding fields):
71+
> price
72+
Field type (enter ? to see all types) [string]:
73+
> float
74+
Can this field be null in the database (nullable) (yes/no) [no]:
75+
> no
76+
77+
Add another property? Enter the property name (or press <return> to stop adding fields):
78+
>
79+
```
80+
81+
This generates a `Product` document class in `src/Document/Product.php`:
82+
83+
```php
84+
<?php
85+
86+
namespace App\Document;
87+
88+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
89+
90+
#[ODM\Document(collection: 'product', repositoryClass: ProductRepository::class)]
91+
class Product
92+
{
93+
#[ODM\Id]
94+
public ?string $id = null;
95+
96+
#[ODM\Field(type: 'string')]
97+
private string $name;
98+
99+
#[ODM\Field(type: 'float')]
100+
private float $price;
101+
102+
// Getters and setters...
103+
}
104+
```
105+
106+
You can also add relations (`ReferenceOne`, `ReferenceMany`, `EmbedOne`, `EmbedMany`) between documents by entering `relation` as the field type and following the prompts.
107+
108+
Running `make:document` again on an existing document lets you add more fields to it.
109+
110+
#### Add an Index to a Document
111+
112+
Add a regular, unique, or search index to an existing document:
113+
114+
```bash
115+
php bin/console make:document:index
116+
```
117+
118+
Follow the interactive prompts to select the document, the index type, and the fields to index. After adding an index, remember to run:
119+
120+
```bash
121+
php bin/console doctrine:mongodb:schema:update
122+
```
123+
124+
to create the index in the database.
125+
126+
## License
127+
128+
The MongoDB MakerBundle is licensed under the MIT License. See the LICENSE file for details.
129+
130+
## Support
131+
132+
For issues, feature requests, or questions, please open an issue on the GitHub repository or reach out to the Doctrine community.

0 commit comments

Comments
 (0)