Skip to content

Commit bd9ea95

Browse files
committed
This is the second-half of a fix for a bad merge (merged master into 2.1).
This was fixed by reverting that merge on 2.1, merging 2.1 into master (as normal), then reverting the revert to restore the changes on master. Revert "This reverts an improper merge - master was merged into 2.1 by mistake." This reverts commit 3300ab3.
1 parent ddc5fb1 commit bd9ea95

File tree

7 files changed

+115
-11
lines changed

7 files changed

+115
-11
lines changed

book/installation.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ Distribution:
6060

6161
.. code-block:: bash
6262
63-
php composer.phar create-project symfony/framework-standard-edition /path/to/webroot/Symfony 2.1.x-dev
63+
php composer.phar create-project symfony/framework-standard-edition /path/to/webroot/Symfony dev-master
6464
6565
.. tip::
6666

67-
For an exact version, replace `2.1.x-dev` with the latest Symfony version
67+
For an exact version, replace `dev-master` with the latest Symfony version
6868
(e.g. 2.1.1). For details, see the `Symfony Installation Page`_
6969

7070
This command may take several minutes to run as Composer download the Standard

book/testing.rst

+9-3
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,19 @@ HTTP layer. For a list of services available in your application, use the
415415
Accessing the Profiler Data
416416
~~~~~~~~~~~~~~~~~~~~~~~~~~~
417417

418-
On each request, the Symfony profiler collects and stores a lot of data about
419-
the internal handling of that request. For example, the profiler could be
420-
used to verify that a given page executes less than a certain number of database
418+
On each request, you can enable the Symfony profiler to collect data about the
419+
internal handling of that request. For example, the profiler could be used to
420+
verify that a given page executes less than a certain number of database
421421
queries when loading.
422422

423423
To get the Profiler for the last request, do the following::
424424

425+
// enable the profiler for the very next request
426+
$client->enableProfiler();
427+
428+
$crawler = $client->request('GET', '/profiler');
429+
430+
// get the profile
425431
$profile = $client->getProfile();
426432

427433
For specific details on using the profiler inside a test, see the

cookbook/testing/profiling.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ various things and enforce some metrics.
1111

1212
The Symfony2 :ref:`Profiler <internals-profiler>` gathers a lot of data for
1313
each request. Use this data to check the number of database calls, the time
14-
spent in the framework, ... But before writing assertions, always check that
15-
the profiler is indeed available (it is enabled by default in the ``test``
16-
environment)::
14+
spent in the framework, ... But before writing assertions, enable the profiler
15+
and check that the profiler is indeed available (it is enabled by default in
16+
the ``test`` environment)::
1717

1818
class HelloControllerTest extends WebTestCase
1919
{
2020
public function testIndex()
2121
{
2222
$client = static::createClient();
23+
24+
// Enable the profiler for the next request (it does nothing if the profiler is not available)
25+
$client->enableProfiler();
26+
2327
$crawler = $client->request('GET', '/hello/Fabien');
2428

2529
// ... write some assertions about the Response

quick_tour/the_big_picture.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ have a ``Symfony/`` directory that looks like this:
5959

6060
.. code-block:: bash
6161
62-
$ composer.phar create-project symfony/framework-standard-edition path/to/install 2.1.x-dev
62+
$ composer.phar create-project symfony/framework-standard-edition path/to/install dev-master
6363
6464
# remove the Git history
6565
$ rm -rf .git
6666
67-
For an exact version, replace `2.1.x-dev` with the latest Symfony version
67+
For an exact version, replace `dev-master` with the latest Symfony version
6868
(e.g. 2.1.1). For details, see the `Symfony Installation Page`_
6969

7070
.. tip::

reference/constraints.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ Validation Constraints Reference
4040
constraints/File
4141
constraints/Image
4242

43+
constraints/Luhn
44+
4345
constraints/Callback
4446
constraints/All
4547
constraints/UserPassword
4648
constraints/Valid
4749

4850
The Validator is designed to validate objects against *constraints*.
4951
In real life, a constraint could be: "The cake must not be burned". In
50-
Symfony2, constraints are similar: They are assertions that a condition is
52+
Symfony2, constraints are similar: They are assertions that a condition is
5153
true.
5254

5355
Supported Constraints

reference/constraints/Luhn.rst

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
Luhn
2+
======
3+
4+
This constraint is used to ensure that a credit card number passes the `Luhn algorithm`_.
5+
It is useful as a first step to validating a credit card: before communicating with a
6+
payment gateway.
7+
8+
+----------------+-----------------------------------------------------------------------+
9+
| Applies to | :ref:`property or method<validation-property-target>` |
10+
+----------------+-----------------------------------------------------------------------+
11+
| Options | - `message`_ |
12+
+----------------+-----------------------------------------------------------------------+
13+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\Luhn` |
14+
+----------------+-----------------------------------------------------------------------+
15+
| Validator | :class:`Symfony\\Component\\Validator\\Constraints\\LuhnValidator` |
16+
+----------------+-----------------------------------------------------------------------+
17+
18+
Basic Usage
19+
-----------
20+
21+
To use the Luhn validator, simply apply it to a property on an object that
22+
will contain a credit card number.
23+
24+
.. configuration-block::
25+
26+
.. code-block:: yaml
27+
28+
# src/Acme/SubscriptionBundle/Resources/config/validation.yml
29+
Acme\SubscriptionBundle\Entity\Transaction:
30+
properties:
31+
cardNumber:
32+
- Luhn:
33+
message: Please check your credit card number.
34+
35+
.. code-block:: xml
36+
37+
<!-- src/Acme/SubscriptionBundle/Resources/config/validation.xml -->
38+
<class name="Acme\SubscriptionBundle\Entity\Transaction">
39+
<property name="cardNumber">
40+
<constraint name="Luhn">
41+
<option name="message">Please check your credit card number.</option>
42+
</constraint>
43+
</property>
44+
</class>
45+
46+
.. code-block:: php-annotations
47+
48+
// src/Acme/SubscriptionBundle/Entity/Transaction.php
49+
use Symfony\Component\Validator\Constraints as Assert;
50+
51+
class Transaction
52+
{
53+
/**
54+
* @Assert\Luhn(message = "Please check your credit card number.")
55+
*/
56+
protected $cardNumber;
57+
}
58+
59+
.. code-block:: php
60+
61+
// src/Acme/SubscriptionBundle/Entity/Transaction.php
62+
use Symfony\Component\Validator\Mapping\ClassMetadata;
63+
use Symfony\Component\Validator\Constraints\Luhn;
64+
65+
class Transaction
66+
{
67+
protected $cardNumber;
68+
69+
public static function loadValidatorMetadata(ClassMetadata $metadata)
70+
{
71+
$metadata->addPropertyConstraint('luhn', new Luhn(array(
72+
'message' => 'Please check your credit card number',
73+
)));
74+
}
75+
}
76+
77+
Available Options
78+
-----------------
79+
80+
message
81+
~~~~~~~
82+
83+
**type**: ``string`` **default**: ``Invalid card number``
84+
85+
The default message supplied when the value does not pass the Luhn check.
86+
87+
.. _`Luhn algorithm`: http://en.wikipedia.org/wiki/Luhn_algorithm

reference/constraints/map.rst.inc

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ File Constraints
5454
* :doc:`File </reference/constraints/File>`
5555
* :doc:`Image </reference/constraints/Image>`
5656

57+
Financial Constraints
58+
~~~~~~~~~~~~~~~~~~~~~
59+
60+
* :doc:`Luhn </reference/constraints/Luhn>`
61+
5762
Other Constraints
5863
~~~~~~~~~~~~~~~~~
5964

0 commit comments

Comments
 (0)