Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06f3bcb

Browse files
committed
updated annotations
1 parent 16ccd4d commit 06f3bcb

File tree

15 files changed

+199
-135
lines changed

15 files changed

+199
-135
lines changed

book/doctrine/orm.rst

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,22 @@ write mapping information with annotations, XML, or YAML:
8888
// src/Acme/HelloBundle/Entity/User.php
8989
namespace Acme\HelloBundle\Entity;
9090
91+
use Doctrine\ORM\Mapping as ORM;
92+
9193
/**
92-
* @orm:Entity
94+
* @ORM\Entity
9395
*/
9496
class User
9597
{
9698
/**
97-
* @orm:Id
98-
* @orm:Column(type="integer")
99-
* @orm:GeneratedValue(strategy="AUTO")
99+
* @ORM\Id
100+
* @ORM\Column(type="integer")
101+
* @ORM\GeneratedValue(strategy="AUTO")
100102
*/
101103
protected $id;
102104
103105
/**
104-
* @orm:Column(type="string", length="255")
106+
* @ORM\Column(type="string", length="255")
105107
*/
106108
protected $name;
107109
}
@@ -218,10 +220,12 @@ losing your existing data. So first let's just add a new property to our
218220
// src/Acme/HelloBundle/Entity/User.php
219221
namespace Acme\HelloBundle\Entity;
220222
221-
/** @orm:Entity */
223+
use Doctrine\ORM\Mapping as ORM;
224+
225+
/** @ORM\Entity */
222226
class User
223227
{
224-
/** @orm:Column(type="string") */
228+
/** @ORM\Column(type="string") */
225229
protected $new;
226230
227231
// ...
@@ -315,8 +319,10 @@ add the name of the repository class to your mapping definition.
315319
// src/Acme/HelloBundle/Entity/User.php
316320
namespace Acme\HelloBundle\Entity;
317321
322+
use Doctrine\ORM\Mapping as ORM;
323+
318324
/**
319-
* @orm:Entity(repositoryClass="Acme\HelloBundle\Repository\UserRepository")
325+
* @ORM\Entity(repositoryClass="Acme\HelloBundle\Repository\UserRepository")
320326
*/
321327
class User
322328
{

book/forms.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,18 @@ number:
306306
.. code-block:: php-annotations
307307
308308
// Acme/StoreBundle/Entity/Product.php
309+
use Symfony\Component\Validator\Constraints as Assert;
310+
309311
class Product
310312
{
311313
/**
312-
* @assert:NotBlank()
314+
* @Assert\NotBlank()
313315
*/
314316
public $name;
315317
316318
/**
317-
* @assert:NotBlank()
318-
* @assert:Min(0)
319+
* @Assert\NotBlank()
320+
* @Assert\Min(0)
319321
*/
320322
protected $price;
321323
}
@@ -728,10 +730,12 @@ Suppose that each ``Product`` belongs to a simple ``Category`` object:
728730
// src/Acme/StoreBundle/Entity/Category.php
729731
namespace Acme\StoreBundle\Entity;
730732
733+
use Symfony\Component\Validator\Constraints as Assert;
734+
731735
class Category
732736
{
733737
/**
734-
* @assert:NotBlank()
738+
* @Assert\NotBlank()
735739
*/
736740
public $name;
737741
}
@@ -740,13 +744,15 @@ The ``Product`` class has a new ``$category`` property, indicating to which
740744
``Category`` it belongs:
741745

742746
.. code-block:: php
743-
747+
748+
use Symfony\Component\Validator\Constraints as Assert;
749+
744750
class Product
745751
{
746752
// ...
747753
748754
/**
749-
* @assert:Type(type="Acme\StoreBundle\Entity\Category")
755+
* @Assert\Type(type="Acme\StoreBundle\Entity\Category")
750756
*/
751757
protected $category;
752758

book/security.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,10 @@ which can secure your controller using annotations:
740740

741741
.. code-block:: php
742742
743+
use JMS\SecurityExtraBundle\Annotation\Secure;
744+
743745
/**
744-
* @extra:Secure(roles="ROLE_ADMIN")
746+
* @Secure(roles="ROLE_ADMIN")
745747
*/
746748
public function helloAction($name)
747749
{
@@ -875,17 +877,18 @@ be stored in the database.
875877
.. code-block:: php
876878
877879
// src/Acme/UserBundle/Entity/User.php
878-
879880
namespace Acme\UserBundle\Entity;
881+
880882
use Symfony\Component\Security\Core\User\UserInterface;
883+
use Doctrine\ORM\Mapping as ORM;
881884
882885
/**
883-
* @orm:Entity
886+
* @ORM\Entity
884887
*/
885888
class User implements UserInterface
886889
{
887890
/**
888-
* @orm:Column(type="string", length="255")
891+
* @ORM\Column(type="string", length="255")
889892
*/
890893
protected $username;
891894

book/validation.rst

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ the ``$name`` property is not empty, add the following:
6161
.. code-block:: php-annotations
6262
6363
// Acme/BlogBundle/Author.php
64+
use Symfony\Component\Validator\Constraints as Assert;
65+
6466
class Author
6567
{
6668
/**
67-
* @assert:NotBlank()
69+
* @Assert\NotBlank()
6870
*/
6971
public $name;
7072
}
@@ -309,10 +311,12 @@ another property, ``gender`` that can be set to either "male" or "female":
309311
.. code-block:: php-annotations
310312
311313
// Acme/BlogBundle/Author.php
314+
use Symfony\Component\Validator\Constraints as Assert;
315+
312316
class Author
313317
{
314318
/**
315-
* @assert:Choice(
319+
* @Assert\Choice(
316320
* choices = { "male", "female" },
317321
* message = "Choose a valid gender."
318322
* )
@@ -369,10 +373,12 @@ options can be specified in this way.
369373
.. code-block:: php-annotations
370374
371375
// Acme/BlogBundle/Author.php
376+
use Symfony\Component\Validator\Constraints as Assert;
377+
372378
class Author
373379
{
374380
/**
375-
* @assert:Choice({"male", "female"})
381+
* @Assert\Choice({"male", "female"})
376382
*/
377383
protected $gender;
378384
}
@@ -451,17 +457,19 @@ of a class ``Author`` to have at least 3 characters.
451457
.. code-block:: php-annotations
452458
453459
// Acme/BlogBundle/Author.php
460+
use Symfony\Component\Validator\Constraints as Assert;
461+
454462
class Author
455463
{
456464
/**
457-
* @assert:NotBlank()
458-
* @assert:MinLength(3)
465+
* @Assert\NotBlank()
466+
* @Assert\MinLength(3)
459467
*/
460468
private $firstName;
461469
462470
/**
463-
* @assert:NotBlank()
464-
* @assert:MinLength(3)
471+
* @Assert\NotBlank()
472+
* @Assert\MinLength(3)
465473
*/
466474
private $lastName;
467475
}
@@ -530,10 +538,12 @@ constraint to validate whether a dynamically generated token is correct:
530538
.. code-block:: php-annotations
531539
532540
// Acme/BlogBundle/Author.php
541+
use Symfony\Component\Validator\Constraints as Assert;
542+
533543
class Author
534544
{
535545
/**
536-
* @assert:True(message = "The token is invalid")
546+
* @Assert\True(message = "The token is invalid")
537547
*/
538548
public function isTokenValid()
539549
{

cookbook/doctrine/reverse_engineering.rst

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ The generated ``BlogPost.dcm.xml`` metadata file looks as follows:
7676
.. code-block:: xml
7777
7878
<?xml version="1.0" encoding="utf-8"?>
79-
<doctrine-mapping>
80-
<entity name="BlogPost" table="blog_post">
81-
<change-tracking-policy>DEFERRED_IMPLICIT</change-tracking-policy>
82-
<id name="id" type="bigint" column="id">
83-
<generator strategy="IDENTITY"/>
84-
</id>
85-
<field name="title" type="string" column="title" length="100"/>
86-
<field name="content" type="text" column="content"/>
87-
<field name="isPublished" type="boolean" column="is_published"/>
88-
<field name="createdAt" type="datetime" column="created_at"/>
89-
<field name="updatedAt" type="datetime" column="updated_at"/>
90-
<field name="slug" type="string" column="slug" length="255"/>
91-
<lifecycle-callbacks/>
92-
</entity>
93-
</doctrine-mapping>
79+
<doctrine-mapping>
80+
<entity name="BlogPost" table="blog_post">
81+
<change-tracking-policy>DEFERRED_IMPLICIT</change-tracking-policy>
82+
<id name="id" type="bigint" column="id">
83+
<generator strategy="IDENTITY"/>
84+
</id>
85+
<field name="title" type="string" column="title" length="100"/>
86+
<field name="content" type="text" column="content"/>
87+
<field name="isPublished" type="boolean" column="is_published"/>
88+
<field name="createdAt" type="datetime" column="created_at"/>
89+
<field name="updatedAt" type="datetime" column="updated_at"/>
90+
<field name="slug" type="string" column="slug" length="255"/>
91+
<lifecycle-callbacks/>
92+
</entity>
93+
</doctrine-mapping>
9494
9595
Once the metadata files are generated, you can ask Doctrine to import the
9696
schema and build related entity classes by executing the following two commands.
@@ -108,57 +108,57 @@ The newly created ``BlogComment`` entity class looks as follow:
108108
109109
<?php
110110
111-
// src/Acme/BlogBundle/Entity/BlogComment.php
112-
namespace Acme\BlogBundle\Entity;
113-
114-
/**
115-
* Acme\BlogBundle\Entity\BlogComment
116-
*
117-
* @orm:Table(name="blog_comment")
118-
* @orm:Entity
119-
*/
120-
class BlogComment
121-
{
122-
/**
123-
* @var bigint $id
124-
*
125-
* @orm:Column(name="id", type="bigint", nullable=false)
126-
* @orm:Id
127-
* @orm:GeneratedValue(strategy="IDENTITY")
128-
*/
129-
private $id;
130-
131-
/**
132-
* @var string $author
133-
*
134-
* @orm:Column(name="author", type="string", length=100, nullable=false)
135-
*/
136-
private $author;
137-
138-
/**
139-
* @var text $content
140-
*
141-
* @orm:Column(name="content", type="text", nullable=false)
142-
*/
143-
private $content;
144-
145-
/**
146-
* @var datetime $createdAt
147-
*
148-
* @orm:Column(name="created_at", type="datetime", nullable=false)
149-
*/
150-
private $createdAt;
151-
152-
/**
153-
* @var BlogPost
154-
*
155-
* @orm:ManyToOne(targetEntity="BlogPost")
156-
* @orm:JoinColumns({
157-
* @orm:JoinColumn(name="post_id", referencedColumnName="id")
158-
* })
159-
*/
160-
private $post;
161-
}
111+
// src/Acme/BlogBundle/Entity/BlogComment.php
112+
namespace Acme\BlogBundle\Entity;
113+
114+
use Doctrine\ORM\Mapping as ORM;
115+
116+
/**
117+
* Acme\BlogBundle\Entity\BlogComment
118+
*
119+
* @ORM\Table(name="blog_comment")
120+
* @ORM\Entity
121+
*/
122+
class BlogComment
123+
{
124+
/**
125+
* @var bigint $id
126+
*
127+
* @ORM\Column(name="id", type="bigint", nullable=false)
128+
* @ORM\Id
129+
* @ORM\GeneratedValue(strategy="IDENTITY")
130+
*/
131+
private $id;
132+
133+
/**
134+
* @var string $author
135+
*
136+
* @ORM\Column(name="author", type="string", length=100, nullable=false)
137+
*/
138+
private $author;
139+
140+
/**
141+
* @var text $content
142+
*
143+
* @ORM\Column(name="content", type="text", nullable=false)
144+
*/
145+
private $content;
146+
147+
/**
148+
* @var datetime $createdAt
149+
*
150+
* @ORM\Column(name="created_at", type="datetime", nullable=false)
151+
*/
152+
private $createdAt;
153+
154+
/**
155+
* @var BlogPost
156+
*
157+
* @ORM\ManyToOne(targetEntity="BlogPost")
158+
* @ORM\JoinColumn(name="post_id", referencedColumnName="id")
159+
*/
160+
private $post;
161+
}
162162
163163
As you can see, Doctrine converts all table fields to pure private and annotated
164164
class properties. The most impressive thing is that it also discovered the

0 commit comments

Comments
 (0)