Skip to content

Commit c50d0a3

Browse files
committed
feature #817 Added more great Symfony 4.1 features (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #817). Discussion ---------- Added more great Symfony 4.1 features The last remaining big features are: * Messenger component: is being discussed in #808. * Advanced Console Output: I plan to send another PR with some changes in some commands. Commits ------- 87b0e03 Added more great Symfony 4.1 features
2 parents 6c86a55 + 87b0e03 commit c50d0a3

File tree

7 files changed

+26
-7
lines changed

7 files changed

+26
-7
lines changed

config/packages/framework.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ framework:
2525
# When 'ide' is set to null the file is opened in your web browser.
2626
# See https://symfony.com/doc/current/reference/configuration/framework.html#ide
2727
ide: ~
28-
validation: { enable_annotations: true }
28+
validation:
29+
email_validation_mode: 'html5'
30+
enable_annotations: true

config/packages/prod/monolog.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ monolog:
44
type: fingers_crossed
55
action_level: error
66
handler: nested
7-
excluded_404s:
8-
# regex: exclude all 404 errors from the logs
9-
- ^/
7+
excluded_http_codes: [404]
108
nested:
119
type: stream
1210
path: '%kernel.logs_dir%/%kernel.environment%.log'

src/Controller/Admin/BlogController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function new(Request $request): Response
114114
/**
115115
* Finds and displays a Post entity.
116116
*
117-
* @Route("/{id}", requirements={"id": "\d+"}, methods={"GET"}, name="admin_post_show")
117+
* @Route("/{id<\d+>}", methods={"GET"}, name="admin_post_show")
118118
*/
119119
public function show(Post $post): Response
120120
{
@@ -130,7 +130,7 @@ public function show(Post $post): Response
130130
/**
131131
* Displays a form to edit an existing Post entity.
132132
*
133-
* @Route("/{id}/edit", requirements={"id": "\d+"}, methods={"GET", "POST"}, name="admin_post_edit")
133+
* @Route("/{id<\d+>}/edit",methods={"GET", "POST"}, name="admin_post_edit")
134134
* @IsGranted("edit", subject="post", message="Posts can only be edited by their authors.")
135135
*/
136136
public function edit(Request $request, Post $post): Response

src/Controller/BlogController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BlogController extends AbstractController
3939
/**
4040
* @Route("/", defaults={"page": "1", "_format"="html"}, methods={"GET"}, name="blog_index")
4141
* @Route("/rss.xml", defaults={"page": "1", "_format"="xml"}, methods={"GET"}, name="blog_rss")
42-
* @Route("/page/{page}", defaults={"_format"="html"}, requirements={"page": "[1-9]\d*"}, methods={"GET"}, name="blog_index_paginated")
42+
* @Route("/page/{page<[1-9]\d*>}", defaults={"_format"="html"}, methods={"GET"}, name="blog_index_paginated")
4343
* @Cache(smaxage="10")
4444
*
4545
* NOTE: For standard formats, Symfony will also automatically choose the best

src/Entity/Post.php

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Post
7070
*
7171
* @ORM\Column(type="string")
7272
* @Assert\NotBlank(message="post.blank_summary")
73+
* @Assert\Length(max=255)
7374
*/
7475
private $summary;
7576

src/Entity/User.php

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\ORM\Mapping as ORM;
1515
use Symfony\Component\Security\Core\User\UserInterface;
16+
use Symfony\Component\Validator\Constraints as Assert;
1617

1718
/**
1819
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
@@ -42,20 +43,24 @@ class User implements UserInterface, \Serializable
4243
* @var string
4344
*
4445
* @ORM\Column(type="string")
46+
* @Assert\NotBlank()
4547
*/
4648
private $fullName;
4749

4850
/**
4951
* @var string
5052
*
5153
* @ORM\Column(type="string", unique=true)
54+
* @Assert\NotBlank()
55+
* @Assert\Length(min=2, max=50)
5256
*/
5357
private $username;
5458

5559
/**
5660
* @var string
5761
*
5862
* @ORM\Column(type="string", unique=true)
63+
* @Assert\Email()
5964
*/
6065
private $email;
6166

tests/Controller/BlogControllerTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,17 @@ public function testNewComment()
8484

8585
$this->assertSame('Hi, Symfony!', $newComment);
8686
}
87+
88+
public function testAjaxSearch()
89+
{
90+
$client = static::createClient();
91+
$client->xmlHttpRequest('GET', '/en/blog/search', ['q' => 'lorem']);
92+
93+
$results = json_decode($client->getResponse()->getContent(), true);
94+
95+
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
96+
$this->assertCount(1, $results);
97+
$this->assertSame('Lorem ipsum dolor sit amet consectetur adipiscing elit', $results[0]['title']);
98+
$this->assertSame('Jane Doe', $results[0]['author']);
99+
}
87100
}

0 commit comments

Comments
 (0)