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

Skip to content

Commit f9138d3

Browse files
jmikolafabpot
authored andcommitted
[FrameworkBundle] Implemented single-pass config loading with intelligent option merging for FrameworkExtension
Restructured config format to make processing more straightforward. Important changes that might break existing configs: * Added "enabled" option for translator (improves multi-format compat) * Removed hash variation of validation annotations option (only boolean) * Moved namespace option directly under validation (improves multi-format compat) The new merge process depends on an internal array of all supported options and their default values, which is used for both validating the config schema and inferring how to merge options (as an added benefit, it helps make the extension self-documenting). Exceptions will now be thrown for merge errors resulting from unrecognized options or invalid types. Since incoming configurations are all merged atop the defaults, many isset() checks were removed. As a rule of thumb, we probably only want to ignore null values when an option would be used to set a parameter. Also: * Added missing attributes to symfony-1.0.xsd * profiler: added only-exceptions attribute * session: fix types and add pdo attributes * Create FrameworkExtension tests with PHP/XML/YAML fixtures * Use "%" syntax instead of calling getParameter() within FrameworkExtension * Normalize config keys and arrays with helper methods for PHP/XML/YAML compatibility Earlier changes: * Remove nonexistent "DependencyInjection/Resources/" path from XmlFileLoaders * Remove hasDefinition() checks, as register methods should only execute once * Remove first-run logic from registerTranslatorConfiguration(), as it is only run once * Removed apparently obsolete clearTags() calls on definitions for non-enabled features
1 parent 199e6bf commit f9138d3

15 files changed

+865
-414
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 400 additions & 371 deletions
Large diffs are not rendered by default.

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,50 @@
99

1010
<xsd:complexType name="config">
1111
<xsd:all>
12-
<xsd:element name="router" type="router" minOccurs="0" maxOccurs="1" />
13-
<xsd:element name="validation" type="validation" minOccurs="0" maxOccurs="1" />
12+
<xsd:element name="csrf-protection" type="csrf_protection" minOccurs="0" maxOccurs="1" />
13+
<xsd:element name="esi" type="esi" minOccurs="0" maxOccurs="1" />
1414
<xsd:element name="profiler" type="profiler" minOccurs="0" maxOccurs="1" />
15+
<xsd:element name="router" type="router" minOccurs="0" maxOccurs="1" />
1516
<xsd:element name="session" type="session" minOccurs="0" maxOccurs="1" />
1617
<xsd:element name="templating" type="templating" minOccurs="0" maxOccurs="1" />
1718
<xsd:element name="translator" type="translator" minOccurs="0" maxOccurs="1" />
18-
<xsd:element name="csrf-protection" type="csrf_protection" minOccurs="0" maxOccurs="1" />
19-
<xsd:element name="esi" type="esi" minOccurs="0" maxOccurs="1" />
19+
<xsd:element name="validation" type="validation" minOccurs="0" maxOccurs="1" />
2020
</xsd:all>
2121

22-
<xsd:attribute name="ide" type="xsd:string" />
22+
<xsd:attribute name="cache-warmer" type="cache_warmer" />
2323
<xsd:attribute name="charset" type="xsd:string" />
2424
<xsd:attribute name="error-handler" type="xsd:string" />
25-
<xsd:attribute name="cache-warmer" type="cache_warmer" />
25+
<xsd:attribute name="ide" type="xsd:string" />
2626
</xsd:complexType>
2727

2828
<xsd:simpleType name="cache_warmer">
2929
<xsd:restriction base="xsd:string">
3030
<xsd:enumeration value="false" />
31-
<xsd:enumeration value="true" />
3231
<xsd:enumeration value="full" />
32+
<xsd:enumeration value="true" />
3333
</xsd:restriction>
3434
</xsd:simpleType>
3535

36+
<xsd:complexType name="csrf_protection">
37+
<xsd:attribute name="enabled" type="xsd:boolean" />
38+
<xsd:attribute name="field-name" type="xsd:string" />
39+
<xsd:attribute name="secret" type="xsd:string" />
40+
</xsd:complexType>
41+
42+
<xsd:complexType name="esi">
43+
<xsd:attribute name="enabled" type="xsd:boolean" />
44+
</xsd:complexType>
45+
46+
<xsd:complexType name="param_converter">
47+
<xsd:attribute name="enabled" type="xsd:boolean" />
48+
</xsd:complexType>
49+
3650
<xsd:complexType name="profiler">
3751
<xsd:all>
3852
<xsd:element name="matcher" type="profiler_matcher" minOccurs="0" maxOccurs="1" />
3953
</xsd:all>
54+
55+
<xsd:attribute name="only-exceptions" type="xsd:boolean" />
4056
</xsd:complexType>
4157

4258
<xsd:complexType name="profiler_matcher">
@@ -51,11 +67,6 @@
5167
<xsd:attribute name="cache-warmer" type="cache_warmer" />
5268
</xsd:complexType>
5369

54-
<xsd:complexType name="validation">
55-
<xsd:attribute name="enabled" type="xsd:boolean" />
56-
<xsd:attribute name="annotations" type="xsd:boolean" />
57-
</xsd:complexType>
58-
5970
<xsd:complexType name="session">
6071
<xsd:attribute name="class" type="xsd:string" />
6172
<xsd:attribute name="storage-id" type="xsd:string" />
@@ -64,11 +75,14 @@
6475
<xsd:attribute name="lifetime" type="xsd:integer" />
6576
<xsd:attribute name="path" type="xsd:string" />
6677
<xsd:attribute name="domain" type="xsd:string" />
67-
<xsd:attribute name="secure" type="xsd:string" />
68-
<xsd:attribute name="httponly" type="xsd:string" />
78+
<xsd:attribute name="secure" type="xsd:boolean" />
79+
<xsd:attribute name="httponly" type="xsd:boolean" />
6980
<xsd:attribute name="cache-limiter" type="xsd:string" />
7081
<xsd:attribute name="auto-start" type="xsd:boolean" />
7182
<xsd:attribute name="pdo.db-table" type="xsd:string" />
83+
<xsd:attribute name="pdo.db-id-col" type="xsd:string" />
84+
<xsd:attribute name="pdo.db-data-col" type="xsd:string" />
85+
<xsd:attribute name="pdo.db-time-col" type="xsd:string" />
7286
</xsd:complexType>
7387

7488
<xsd:complexType name="templating">
@@ -83,21 +97,26 @@
8397
<xsd:attribute name="cache-warmer" type="cache_warmer" />
8498
</xsd:complexType>
8599

86-
<xsd:complexType name="translator">
87-
<xsd:attribute name="fallback" type="xsd:string" />
100+
<xsd:complexType name="templating_engine">
101+
<xsd:attribute name="id" type="xsd:string" />
88102
</xsd:complexType>
89103

90-
<xsd:complexType name="csrf_protection">
104+
<xsd:complexType name="translator">
91105
<xsd:attribute name="enabled" type="xsd:boolean" />
92-
<xsd:attribute name="field-name" type="xsd:string" />
93-
<xsd:attribute name="secret" type="xsd:string" />
106+
<xsd:attribute name="fallback" type="xsd:string" />
94107
</xsd:complexType>
95108

96-
<xsd:complexType name="esi">
109+
<xsd:complexType name="validation">
110+
<xsd:sequence>
111+
<xsd:element name="namespace" type="validation_namespace" minOccurs="0" maxOccurs="1" />
112+
</xsd:sequence>
113+
97114
<xsd:attribute name="enabled" type="xsd:boolean" />
115+
<xsd:attribute name="annotations" type="xsd:boolean" />
98116
</xsd:complexType>
99117

100-
<xsd:complexType name="templating_engine">
101-
<xsd:attribute name="id" type="xsd:string" />
118+
<xsd:complexType name="validation_namespace">
119+
<xsd:attribute name="prefix" type="xsd:string" />
120+
<xsd:attribute name="namespace" type="xsd:string" />
102121
</xsd:complexType>
103122
</xsd:schema>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
$container->loadFromExtension('app', 'config', array(
4+
'csrf_protection' => array(
5+
'enabled' => true,
6+
'field_name' => '_csrf',
7+
'secret' => 's3cr3t',
8+
),
9+
'esi' => array(
10+
'enabled' => true,
11+
),
12+
'profiler' => array(
13+
'only_exceptions' => true,
14+
),
15+
'router' => array(
16+
'resource' => '%kernel.root_dir%/config/routing.xml',
17+
'cache_warmer' => true,
18+
),
19+
'session' => array(
20+
'auto_start' => true,
21+
'class' => 'Session',
22+
'default_locale' => 'fr',
23+
'storage_id' => 'native',
24+
'name' => '_SYMFONY',
25+
'lifetime' => 86400,
26+
'path' => '/',
27+
'domain' => 'example.com',
28+
'secure' => true,
29+
'httponly' => true,
30+
),
31+
'templating' => array(
32+
'assets_version' => 'SomeVersionScheme',
33+
'assets_base_urls' => 'http://cdn.example.com',
34+
'cache_warmer' => true,
35+
'engines' => array('php', 'twig'),
36+
'loader' => array('loader.foo', 'loader.bar'),
37+
),
38+
'translator' => array(
39+
'enabled' => true,
40+
'fallback' => 'fr',
41+
),
42+
'validation' => array(
43+
'enabled' => true,
44+
),
45+
));
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
$container->loadFromExtension('app', 'config', array(
4+
'router' => array(
5+
'resource' => '%kernel.root_dir%/config/routing.xml',
6+
),
7+
'session' => array(
8+
'storage_id' => 'pdo',
9+
'pdo.db_table' => 'table',
10+
'pdo.db_id_col' => 'id',
11+
'pdo.db_data_col' => 'data',
12+
'pdo.db_time_col' => 'time',
13+
),
14+
'templating' => array(
15+
'engine' => 'php'
16+
),
17+
));
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
$container->loadFromExtension('app', 'config', array(
4+
'router' => array(
5+
'resource' => '%kernel.root_dir%/config/routing.xml',
6+
),
7+
'validation' => array(
8+
'enabled' => true,
9+
'annotations' => true,
10+
'namespaces' => array(
11+
'app' => 'Application\\Validator\\Constraints\\',
12+
),
13+
),
14+
'templating' => array(
15+
'engine' => 'php'
16+
),
17+
));
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://www.symfony-project.org/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:app="http://www.symfony-project.org/schema/dic/symfony"
6+
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd
7+
http://www.symfony-project.org/schema/dic/symfony http://www.symfony-project.org/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<app:config>
10+
<app:csrf-protection enabled="true" field-name="_csrf" secret="s3cr3t" />
11+
<app:esi enabled="true" />
12+
<app:profiler only-exceptions="true" />
13+
<app:router resource="%kernel.root_dir%/config/routing.xml" cache-warmer="true" />
14+
<app:session auto-start="true" class="Session" default-locale="fr" storage-id="native" name="_SYMFONY" lifetime="86400" path="/" domain="example.com" secure="true" httponly="true" />
15+
<app:templating assets-version="SomeVersionScheme" assets-base-urls="http://cdn.example.com" cache-warmer="true">
16+
<app:loader>loader.foo</app:loader>
17+
<app:loader>loader.bar</app:loader>
18+
<app:engine id="php" />
19+
<app:engine id="twig" />
20+
</app:templating>
21+
<app:translator enabled="true" fallback="fr" />
22+
<app:validation enabled="true" />
23+
</app:config>
24+
</container>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://www.symfony-project.org/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:app="http://www.symfony-project.org/schema/dic/symfony"
6+
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd
7+
http://www.symfony-project.org/schema/dic/symfony http://www.symfony-project.org/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<app:config>
10+
<app:router resource="%kernel.root_dir%/config/routing.xml" />
11+
<app:session storage-id="pdo" pdo.db-table="table" pdo.db-id-col="id" pdo.db-data-col="data" pdo.db-time-col="time" />
12+
<app:templating>
13+
<app:engine id="php" />
14+
</app:templating>
15+
</app:config>
16+
</container>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://www.symfony-project.org/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:app="http://www.symfony-project.org/schema/dic/symfony"
6+
xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd
7+
http://www.symfony-project.org/schema/dic/symfony http://www.symfony-project.org/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<app:config>
10+
<app:router resource="%kernel.root_dir%/config/routing.xml" />
11+
<app:validation enabled="true" annotations="true">
12+
<app:namespace prefix="app" namespace="Application\Validator\Constraints\" />
13+
</app:validation>
14+
<app:templating>
15+
<app:engine id="php" />
16+
</app:templating>
17+
</app:config>
18+
</container>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
app.config:
2+
csrf_protection:
3+
enabled: true
4+
field_name: _csrf
5+
secret: s3cr3t
6+
esi:
7+
enabled: true
8+
profiler:
9+
only_exceptions: true
10+
router:
11+
resource: %kernel.root_dir%/config/routing.xml
12+
cache_warmer: true
13+
session:
14+
auto_start: true
15+
class: Session
16+
default_locale: fr
17+
storage_id: native
18+
name: _SYMFONY
19+
lifetime: 86400
20+
path: /
21+
domain: example.com
22+
secure: true
23+
httponly: true
24+
templating:
25+
assets_version: SomeVersionScheme
26+
assets_base_urls: http://cdn.example.com
27+
cache_warmer: true
28+
engines: [php, twig]
29+
loader: [loader.foo, loader.bar]
30+
translator:
31+
enabled: true,
32+
fallback: fr
33+
validation:
34+
enabled: true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
app.config:
2+
router:
3+
resource: %kernel.root_dir%/config/routing.xml
4+
session:
5+
storage_id: pdo
6+
pdo.db_table: table
7+
pdo.db_id_col: id
8+
pdo.db_data_col: data
9+
pdo.db_time_col: time
10+
templating:
11+
engine: php
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
app.config:
2+
router:
3+
resource: %kernel.root_dir%/config/routing.xml
4+
validation:
5+
enabled: true
6+
annotations: true
7+
namespaces:
8+
app: Application\Validator\Constraints\
9+
templating:
10+
engine: php

0 commit comments

Comments
 (0)