Skip to content

Commit ac188e9

Browse files
committed
feature #562 Updated the application to Symfony 3.3.0 (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #562). Discussion ---------- Updated the application to Symfony 3.3.0 This finishes #483 and uses the all the new 3.3 features for DI services. Commits ------- 6979117 Updated the application to Symfony 3.3.0
2 parents 98898e4 + 6979117 commit ac188e9

18 files changed

+489
-268
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ script:
2929
- ./bin/console lint:yaml @CodeExplorerBundle
3030
# this checks that the Twig template files contain no syntax errors
3131
- ./bin/console lint:twig app/Resources @CodeExplorerBundle
32+
# this checks that the XLIFF translations contain no syntax errors
33+
- ./bin/console lint:xliff app/Resources
3234
# this checks that the application doesn't use dependencies with known security vulnerabilities
3335
- ./bin/console security:check --end-point=http://security.sensiolabs.org/check_lock

app/AppKernel.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ public function registerBundles()
4242
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
4343
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
4444
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
45-
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
45+
46+
if ('dev' === $this->getEnvironment()) {
47+
$bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
48+
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
49+
}
4650

4751
if ('test' === $this->getEnvironment()) {
4852
// this bundle makes it easier to work with databases in PHPUnit

app/config/config.yml

+20-21
Original file line numberDiff line numberDiff line change
@@ -30,51 +30,50 @@ framework:
3030
# and with different cache configurations for each fragment
3131
# https://symfony.com/doc/current/book/http_cache.html#edge-side-includes
3232
esi: { enabled: true }
33-
translator: { fallback: "%locale%" }
34-
secret: "%env(SYMFONY_SECRET)%"
33+
translator: { fallback: '%locale%' }
34+
secret: '%env(SYMFONY_SECRET)%'
3535
router:
36-
resource: "%kernel.root_dir%/config/routing.yml"
36+
resource: '%kernel.root_dir%/config/routing.yml'
3737
strict_requirements: ~
3838
form: ~
3939
csrf_protection: ~
4040
validation: { enable_annotations: true }
4141
templating:
4242
engines: ['twig']
43-
default_locale: "%locale%"
43+
default_locale: '%locale%'
4444
trusted_hosts: ~
45-
trusted_proxies: ~
4645
session:
4746
handler_id: session.handler.native_file
48-
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
47+
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
4948
fragments: ~
5049
http_method_override: true
5150
assets: ~
5251

5352
# Twig Configuration (used for rendering application templates)
5453
twig:
55-
debug: "%kernel.debug%"
56-
strict_variables: "%kernel.debug%"
54+
debug: '%kernel.debug%'
55+
strict_variables: '%kernel.debug%'
5756
form_themes:
58-
- "form/layout.html.twig"
59-
- "form/fields.html.twig"
57+
- 'form/layout.html.twig'
58+
- 'form/fields.html.twig'
6059

6160
# Doctrine Configuration (used to access databases and manipulate their information)
6261
doctrine:
6362
dbal:
6463
# if you don't want to use SQLite, change the URL in parameters.yml or set the DATABASE_URL environment variable
65-
url: "%env(DATABASE_URL)%"
64+
url: '%env(DATABASE_URL)%'
6665

6766
# instead of using a URL, you may also uncomment the following lines to configure your database
6867
# driver: pdo_mysql
69-
# host: "%database_host%"
70-
# port: "%database_port%"
71-
# dbname: "%database_name%"
72-
# user: "%database_user%"
73-
# password: "%database_password%"
68+
# host: '%database_host%'
69+
# port: '%database_port%'
70+
# dbname: '%database_name%'
71+
# user: '%database_user%'
72+
# password: '%database_password%'
7473
# charset: UTF8
7574

7675
orm:
77-
auto_generate_proxy_classes: "%kernel.debug%"
76+
auto_generate_proxy_classes: '%kernel.debug%'
7877
auto_mapping: true
7978

8079
# Swiftmailer Configuration (used to send emails)
@@ -84,8 +83,8 @@ doctrine:
8483
# stores options that change from one server to another
8584
#
8685
swiftmailer:
87-
transport: "%mailer_transport%"
88-
host: "%mailer_host%"
89-
username: "%mailer_user%"
90-
password: "%mailer_password%"
86+
transport: '%mailer_transport%'
87+
host: '%mailer_host%'
88+
username: '%mailer_user%'
89+
password: '%mailer_password%'
9190
spool: { type: memory }

app/config/services.yml

+44-80
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,47 @@
11
services:
2-
# First we define some basic services to make these utilities available in
3-
# the entire application
4-
slugger:
5-
class: AppBundle\Utils\Slugger
6-
7-
markdown:
8-
class: AppBundle\Utils\Markdown
9-
10-
# These are the Twig extensions that create new filters and functions for
11-
# using them in the templates
12-
app.twig.app_extension:
13-
public: false
14-
class: AppBundle\Twig\AppExtension
15-
arguments: ['@markdown', '%app_locales%']
16-
tags:
17-
- { name: twig.extension }
18-
19-
app.twig.intl_extension:
20-
public: false
21-
class: Twig_Extensions_Extension_Intl
22-
tags:
23-
- { name: twig.extension }
24-
25-
# Defining a form type as a service is only required when the form type
26-
# needs to use some other services, such as the entity manager.
27-
# See https://symfony.com/doc/current/best_practices/forms.html
28-
app.form.type.tagsinput:
29-
class: AppBundle\Form\Type\TagsInputType
30-
arguments: ['@doctrine.orm.entity_manager']
31-
tags:
32-
- { name: form.type }
33-
34-
# Event Listeners are classes that listen to one or more specific events.
35-
# Those events are defined in the tags added to the service definition.
36-
# See https://symfony.com/doc/current/event_dispatcher.html#creating-an-event-listener
37-
app.redirect_to_preferred_locale_listener:
38-
class: AppBundle\EventListener\RedirectToPreferredLocaleListener
39-
arguments: ['@router', '%app_locales%', '%locale%']
40-
tags:
41-
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
42-
43-
app.comment_notification:
44-
class: AppBundle\EventListener\CommentNotificationListener
45-
arguments: ['@mailer', '@router', '@translator', '%app.notifications.email_sender%']
46-
# The "method" attribute of this tag is optional and defaults to "on + camelCasedEventName"
47-
# If the event is "comment.created" the method executed by default is "onCommentCreated()".
48-
tags:
49-
- { name: kernel.event_listener, event: comment.created, method: onCommentCreated }
50-
51-
# Event subscribers are similar to event listeners but they don't need service tags.
52-
# Instead, the PHP class of the event subscriber includes a method that returns
53-
# the list of events listened by that class.
54-
# See https://symfony.com/doc/current/event_dispatcher.html#creating-an-event-subscriber
55-
app.requirements_subscriber:
56-
class: AppBundle\EventListener\CheckRequirementsSubscriber
57-
arguments: ['@doctrine.orm.entity_manager']
58-
tags:
59-
- { name: kernel.event_subscriber }
60-
61-
# To inject the voter into the security layer, you must declare it as a service and tag it with security.voter.
62-
# See https://symfony.com/doc/current/security/voters.html#configuring-the-voter
63-
app.post_voter:
64-
class: AppBundle\Security\PostVoter
2+
# default configuration for services in *this* file
3+
_defaults:
4+
# automatically injects dependencies in your services
5+
autowire: true
6+
# automatically registers your services as commands, event subscribers, etc.
7+
autoconfigure: true
8+
# this means you cannot fetch services directly from the container via $container->get()
9+
# if you need to do this, you can override this setting on individual services
6510
public: false
66-
tags:
67-
- { name: security.voter }
6811

69-
# Uncomment the following lines to define a service for the Post Doctrine repository.
70-
# It's not mandatory to create these services, but if you use repositories a lot,
71-
# these services simplify your code:
72-
#
73-
# app.post_repository:
74-
# class: Doctrine\ORM\EntityRepository
75-
# factory: ['@doctrine.orm.entity_manager', getRepository]
76-
# arguments: [AppBundle\Entity\Post]
77-
#
78-
# // traditional code inside a controller
79-
# $entityManager = $this->getDoctrine()->getManager();
80-
# $posts = $entityManager->getRepository('AppBundle:Post')->findAll();
81-
#
82-
# // same code using repository services
83-
# $posts = $this->get('app.post_repository')->findAll();
12+
# makes classes in src/AppBundle available to be used as services
13+
# this creates a service per class whose id is the fully-qualified class name
14+
AppBundle\:
15+
resource: '../../src/AppBundle/*'
16+
# you can exclude directories or files
17+
# but if a service is unused, it's removed anyway
18+
exclude: '../../src/AppBundle/{Controller,Entity,Repository}'
19+
20+
# controllers are imported separately to make sure they're public
21+
# and have a tag that allows actions to type-hint services
22+
AppBundle\Controller\:
23+
resource: '../../src/AppBundle/Controller'
24+
public: true
25+
tags: ['controller.service_arguments']
26+
27+
# Autowiring can't guess the constructor arguments that are not type-hinted with
28+
# classes (e.g. container parameters) so you must define those arguments explicitly
29+
AppBundle\Command\ListUsersCommand:
30+
arguments:
31+
$emailSender: '%app.notifications.email_sender%'
32+
33+
AppBundle\Twig\AppExtension:
34+
arguments:
35+
$locales: '%app_locales%'
36+
37+
AppBundle\EventListener\CommentNotificationSubscriber:
38+
arguments:
39+
$sender: '%app.notifications.email_sender%'
40+
41+
AppBundle\EventListener\RedirectToPreferredLocaleSubscriber:
42+
arguments:
43+
$locales: '%app_locales%'
44+
$defaultLocale: '%locale%'
45+
46+
# needed for the localizeddate Twig filter
47+
Twig\Extensions\IntlExtension: ~

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"symfony/monolog-bundle" : "^3.0",
3030
"symfony/polyfill-apcu" : "^1.0",
3131
"symfony/swiftmailer-bundle" : "^2.3",
32-
"symfony/symfony" : "^3.2",
33-
"twig/extensions" : "^1.3",
32+
"symfony/symfony" : "^3.3",
33+
"twig/extensions" : "^1.5",
3434
"twig/twig" : "^1.28 || ^2.0",
3535
"white-october/pagerfanta-bundle" : "^1.0"
3636
},

0 commit comments

Comments
 (0)