Skip to content
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

Modernize documentation #618

Merged
merged 16 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions Resources/doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ can control. The following configuration options exist for a mapping:
To avoid having to configure lots of information for your mappings you should
follow these conventions:

1. Put all your documents in a directory ``Document/`` inside your bundle. For
example ``Acme/HelloBundle/Document/``.
1. Put all your documents in a directory ``Document/`` inside your project. For
example ``src/Document/``.

2. If you are using xml, yml or php mapping put all your configuration files
into the ``Resources/config/doctrine/`` directory
Expand Down
41 changes: 22 additions & 19 deletions Resources/doc/cookbook/registration_form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ We begin this tutorial with the model for a ``User`` document:

.. code-block:: php

// src/Acme/AccountBundle/Document/User.php
namespace Acme\AccountBundle\Document;
// src/Document/User.php
namespace App\Document;

use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique as MongoDBUnique;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
Expand Down Expand Up @@ -87,10 +87,10 @@ Next, create the form for the ``User`` model:

.. code-block:: php

// src/Acme/AccountBundle/Form/Type/UserType.php
namespace Acme\AccountBundle\Form\Type;
// src/Form/Type/UserType.php
namespace App\Form\Type;

use Acme\AccountBundle\Document\User;
use App\Document\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
Expand Down Expand Up @@ -139,16 +139,16 @@ form and adds the extra field needed:

.. code-block:: php

// src/Acme/AccountBundle/Form/Model/Registration.php
namespace Acme\AccountBundle\Form\Model;
// src/Form/Model/Registration.php
namespace App\Form\Model;

use Acme\AccountBundle\Document\User;
use App\Document\User;
use Symfony\Component\Validator\Constraints as Assert;

class Registration
{
/**
* @Assert\Type(type="Acme\AccountBundle\Document\User")
* @Assert\Type(type="App\Document\User")
*/
protected $user;

Expand Down Expand Up @@ -183,8 +183,8 @@ Next, create the form for this ``Registration`` model:

.. code-block:: php

// src/Acme/AccountBundle/Form/Type/RegistrationType.php
namespace Acme\AccountBundle\Form\Type;
// src/Form/Type/RegistrationType.php
namespace App\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType
Expand Down Expand Up @@ -212,21 +212,22 @@ controller that will display the registration form:

.. code-block:: php

// src/Acme/AccountBundle/Controller/AccountController.php
namespace Acme\AccountBundle\Controller;
// src/Controller/AccountController.php
namespace App\Controller;

use Acme\AccountBundle\Form\Model\Registration;
use Acme\AccountBundle\Form\Type\RegistrationType;
use Doctrine\ODM\MongoDB\DocumentManager;
use App\Form\Model\Registration;
use App\Form\Type\RegistrationType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

class AccountController extends Controller
class AccountController extends AbstractController
{
public function registerAction()
{
$form = $this->createForm(RegistrationType::class, new Registration());

return $this->render('AcmeAccountBundle:Account:register.html.twig', [
return $this->render('Account/register.html.twig', [
'form' => $form->createView()
]);
}
Expand All @@ -236,7 +237,8 @@ and its template:

.. code-block:: html+jinja

{# src/Acme/AccountBundle/Resources/views/Account/register.html.twig #}
{# templates/Account/register.html.twig #}

{{ form_start(form, {'action': path('create'), 'method': 'POST'}) }}
{{ form_widget(form) }}

Expand All @@ -248,6 +250,7 @@ the form submission - perform its validation and save the User into MongoDB:

.. code-block:: php

// src/Controller/AccountController.php
public function createAction(DocumentManager $dm, Request $request)
{
$form = $this->createForm(RegistrationType::class, new Registration());
Expand All @@ -263,7 +266,7 @@ the form submission - perform its validation and save the User into MongoDB:
return $this->redirect(...);
}

return $this->render('AcmeAccountBundle:Account:register.html.twig', [
return $this->render('Account/register.html.twig', [
'form' => $form->createView()
]);
}
Expand Down
6 changes: 3 additions & 3 deletions Resources/doc/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ when its event is dispatched.

services:
my_doctrine_listener:
class: Acme\HelloBundle\Listener\MyDoctrineListener
class: App\Listener\MyDoctrineListener
# ...
tags:
- { name: doctrine_mongodb.odm.event_listener, event: postPersist }

.. code-block:: xml

<service id="my_doctrine_listener" class="Acme\HelloBundle\Listener\MyDoctrineListener">
<service id="my_doctrine_listener" class="App\Listener\MyDoctrineListener">
<!-- ... -->
<tag name="doctrine_mongodb.odm.event_listener" event="postPersist" />
</service>

.. code-block:: php

$definition = new Definition('Acme\HelloBundle\Listener\MyDoctrineListener');
$definition = new Definition('App\Listener\MyDoctrineListener');
// ...
$definition->addTag('doctrine_mongodb.odm.event_listener', [
'event' => 'postPersist',
Expand Down
61 changes: 26 additions & 35 deletions Resources/doc/first_steps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@ The best way to understand the Doctrine MongoDB ODM is to see it in action.
In this section, you'll walk through each step needed to start persisting
documents to and from MongoDB.

.. sidebar:: Code along with the example

If you want to follow along with the example in this chapter, create
an ``AcmeStoreBundle`` via:

.. code-block:: bash

php bin/console generate:bundle --namespace=Acme/StoreBundle

A Simple Example: A Product
An Introductory Example: A Product
---------------------------
SzymonKaminski marked this conversation as resolved.
Show resolved Hide resolved

Creating a Document Class
Expand All @@ -23,12 +14,12 @@ Creating a Document Class
Suppose you're building an application where products need to be displayed.
Without even thinking about Doctrine or MongoDB, you already know that you
need a ``Product`` object to represent those products. Create this class
inside the ``Document`` directory of your ``AcmeStoreBundle``:
inside the ``Document`` subdirectory of your project's source code:

.. code-block:: php

// src/Acme/StoreBundle/Document/Product.php
namespace Acme\StoreBundle\Document;
// src/Document/Product.php
namespace App\Document;

class Product
{
Expand Down Expand Up @@ -61,13 +52,13 @@ in a number of different formats including XML or directly inside the

.. code-block:: xml

<!-- src/Acme/StoreBundle/Resources/config/doctrine/Product.mongodb.xml -->
<!-- src/Resources/config/doctrine/Product.mongodb.xml -->
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
https://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<document name="Acme\StoreBundle\Document\Product">
<document name="App\Document\Product">
<id />
<field fieldName="name" type="string" />
<field fieldName="price" type="float" />
Expand All @@ -76,8 +67,8 @@ in a number of different formats including XML or directly inside the

.. code-block:: php

// src/Acme/StoreBundle/Document/Product.php
namespace Acme\StoreBundle\Document;
// src/Document/Product.php
namespace App\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

Expand Down Expand Up @@ -121,8 +112,8 @@ a controller. Create new Controller class inside source directory of your projec
.. code-block:: php
:linenos:

// src/Acme/StoreBundle/Controller/DefaultController.php
use Acme\StoreBundle\Document\Product;
// src/App/Controller/ProductController.php
use App\Document\Product;
use Doctrine\ODM\MongoDB\DocumentManager;
use Symfony\Component\HttpFoundation\Response;
// ...
Expand Down Expand Up @@ -184,7 +175,7 @@ If you are using `autowiring`, you can use type hinting to fetch the ``doctrine_
$dm->persist($product);
$dm->flush();

return new Response('Created product id '.$product->getId());
return new Response('Created product id ' . $product->getId());
}
}

Expand Down Expand Up @@ -347,7 +338,7 @@ From inside a controller:
->sort('price', 'ASC')
->limit(10)
->getQuery()
->execute()
->execute();

In this case, 10 products with a name of "foo", ordered from lowest price
to highest price are returned.
Expand All @@ -371,10 +362,10 @@ To do this, add the name of the repository class to your mapping definition.

.. code-block:: php-annotations

// src/Acme/StoreBundle/Document/Product.php
namespace Acme\StoreBundle\Document;
// src/Document/Product.php
namespace App\Document;

use Acme\StoreBundle\Repository\ProductRepository;
use App\Repository\ProductRepository;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
Expand All @@ -387,15 +378,15 @@ To do this, add the name of the repository class to your mapping definition.

.. code-block:: xml

<!-- src/Acme/StoreBundle/Resources/config/doctrine/Product.mongodb.xml -->
<!-- src/Resources/config/doctrine/Product.mongodb.xml -->
<!-- ... -->
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
https://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<document name="Acme\StoreBundle\Document\Product"
repository-class="Acme\StoreBundle\Repository\ProductRepository">
<document name="App\Document\Product"
repository-class="App\Repository\ProductRepository">
<!-- ... -->
</document>

Expand All @@ -408,8 +399,8 @@ for all of the ``Product`` documents, ordered alphabetically.

.. code-block:: php

// src/Acme/StoreBundle/Repository/ProductRepository.php
namespace Acme\StoreBundle\Repository;
// src/Repository/ProductRepository.php
namespace App\Repository;

use Doctrine\ODM\MongoDB\Repository\DocumentRepository;

Expand Down Expand Up @@ -446,10 +437,10 @@ is to use the repository as a service and inject it as a dependency into other s

.. code-block:: php

// src/Acme/StoreBundle/Repository/ProductRepository.php
namespace Acme\StoreBundle\Repository;
// src/App/Repository/ProductRepository.php
namespace App\Repository;

use Acme\StoreBundle\Document\Product;
use App\Document\Product;
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
use Doctrine\Bundle\MongoDBBundle\Repository\ServiceDocumentRepository;

Expand Down Expand Up @@ -478,8 +469,8 @@ repositories as services you can use the following service configuration:
autowire: true
autoconfigure: true

Acme\StoreBundle\Repository\:
resource: '%kernel.root_dir%/../src/Acme/StoreBundle/Repository/*'
App\Repository\:
resource: '../src/Repository/*'

.. code-block:: xml

Expand All @@ -492,7 +483,7 @@ repositories as services you can use the following service configuration:
<services>
<defaults autowire="true" autoconfigure="true" />

<prototype namespace="Acme\StoreBundle\Repository\" resource="%kernel.root_dir%/../src/Acme/StoreBundle/Repository/*" />
<prototype namespace="App\Repository\" resource="../src/Repository/*" />
</services>
</container>

Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/security_bundle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ the ``entity`` user provider described in `the cookbook`_:
security:
providers:
my_mongo_provider:
mongodb: {class: Acme\DemoBundle\Document\User, property: username}
mongodb: {class: App\Document\User, property: username}

.. code-block:: xml

<!-- app/config/security.xml -->
<config>
<provider name="my_mongo_provider">
<mongodb class="Acme\DemoBundle\Document\User" property="username" />
<mongodb class="App\Document\User" property="username" />
</provider>
</config>

Expand Down