Commit Graph

447 Commits

Author SHA1 Message Date
Bernhard Schussek
09a50c3c55 [Form] Fixed: "by_reference" option is ignored if reading from/writing to an array 2011-02-08 04:14:55 +01:00
Kris Wallsmith
ef43b22546 [HttpFoundation] fixed test cleanup 2011-02-08 04:14:39 +01:00
pborreli
41bf849a63 [HttpFoundation] Request coverage 2011-02-07 02:49:14 +01:00
Marc Weistroff
bebdcb242d [HttpKernel] Added response cache-control modification if page is composed of ESIs.
Rules are :
- If one of the ESI has validation cache strategy, the whole page will be
forced to validate.
- In none of the ESI has validation, the response will feature a Cache-Control
directive with s-maxage value equals to the smallest TTL of ESIs.
2011-02-07 01:34:14 +01:00
pborreli
7ad4f99153 [HttpFoundation] File/UploadedFile, MimeTest, Exception full coverage 2011-02-06 21:53:36 +01:00
Johannes M. Schmitt
2b256a0804 [DependencyInjection] allow null for scalar nodes 2011-02-06 20:50:03 +01:00
Johannes M. Schmitt
c7ef8d98d6 [DependencyInjection] append new elements for prototype nodes without a key attribute 2011-02-06 20:11:08 +01:00
Johannes Schmitt
0b8fef2347 [Security/DependencyInjection] adds support for merging security configurations
The merging is done in three steps:

    1. Normalization:
    =================
    All passed config arrays will be transformed into the same structure
    regardless of what format they come from.

    2. Merging:
    ===========
    This is the step when the actual merging is performed. Starting at the root
    the configs will be passed along the tree until a node has no children, or
    the merging of sub-paths of the current node has been specifically disabled.

       Left-Side       Right-Side      Merge Result
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       -nothing-       array           Right-Side will be taken.
       scalar          scalar          Right-Side will be taken.
       array           false           Right-Side will be taken if ->canBeUnset()
                                       was called on the array node.
       false           array           Right-Side will be taken.
       array           array           Each value in the array will be passed to
                                       the specific child node, or the prototype
                                       node (whatever is present).

    3. Finalization:
    ================
    The normalized, and merged config will be passed through the config tree to
    perform final validation on the submitted values, and set default values
    where this has been requested.

You can influence this process in various ways, here is a list with some examples.
All of these methods must be called on the node on which they should be applied.

  * isRequired(): Node must be present in at least one config file.
  * requiresAtLeastOneElement(): PrototypeNode must have at least one element.
  * treatNullLike($value): Replaces null with $value during normalization.
  * treatTrueLike($value): Same as above just for true
  * treatFalseLike($value): Same as above just for false
  * defaultValue($value): Sets a default value for this node (only for scalars)
  * addDefaultsIfNotSet(): Whether to add default values of an array which has not
                           been defined in any configuration file.
  * disallowNewKeysInSubsequentConfigs(): All keys for this array must be defined
                                          in one configuration file, subsequent
                                          configurations may only overwrite these.
  * fixXmlConfig($key, $plural = null): Transforms XML config into same structure
                                        as YAML, and PHP configurations.
  * useAttributeAsKey($name): Defines which XML attribute to use as array key.
  * cannotBeOverwritten(): Declares a certain sub-path as non-overwritable. All
                           configuration for this path must be defined in the same
                           configuration file.
  * cannotBeEmpty(): If value is set, it must be non-empty.
  * canBeUnset(): If array values should be unset if false is specified.

Architecture:
=============
The configuration consists basically out of two different sets of classes.

  1. Builder classes: These classes provide the fluent interface and
                      are used to construct the config tree.

  2. Node classes: These classes contain the actual logic for normalization,
                   merging, and finalizing configurations.

After you have added all the metadata to your builders, the call to
->buildTree() will convert this metadata to actual node classes. Most of the
time, you will not have to interact with the config nodes directly, but will
delegate this to the Processor class which will call the respective methods
on the config node classes.
2011-02-06 20:11:08 +01:00
ornicar
c5fb96b86b [HttpKernel] Add more unit tests for Kernel 2011-02-06 20:05:49 +01:00
Bernhard Schussek
74d0ac82f7 [Form] Cleaned up ValueTransformerInterface
This commit removes CollectionToStringTransformer. Transformers should never change the state of the outside world, otherwise hard-to-track bugs might creap in.

This functionality needs to be implemented as a custom FieldType (see EntityChoiceField).
2011-02-06 19:46:29 +01:00
Bernhard Schussek
bd3e6c6b49 [Form] Fixed: Form::bind() throws an exception if form is anonymous 2011-02-06 19:46:28 +01:00
Bernhard Schussek
6ff4120784 [Form] Added Form option "by_reference" so that objects received from parent forms are modified by reference when this option is true (the default)
The implication is that set<Reference>() in the object of the parent form will not be called (and thus not has to be implemented/public).

If you want to suppress this behaviour, manually set "by_reference" to false.
2011-02-06 19:46:28 +01:00
ornicar
9ba2943aff [HttpKernel] Add unit tests for Kernel. Also slightly modify Kernel to make it more testable. 2011-02-06 16:17:35 +01:00
John Kary
c251a36935 [HttpFoundation] Add tests for Cookie 2011-02-06 16:16:05 +01:00
ornicar
bd97471954 [HttpKernel] Add test coverage for cache warming 2011-02-05 23:54:09 +01:00
pborreli
f56a6efbf5 [HttpFoundation] File/File full coverage 2011-02-05 23:24:00 +01:00
Fabien Potencier
e5403490e7 removed the need to define getNamespace() and getPath() in bundles 2011-02-05 22:40:30 +01:00
Jeremy Mikola
743f25a287 [DependencyInjection] Create explicit factoryClass property for Definitions
Previously, the Definition class was used both for type inference and factory construction (if factoryService was absent). This is fine for cases where classes create instances of themselves (e.g. getInstance() or create()), but leads to ambiguity when we have a separate factory class.
2011-02-05 20:39:42 +01:00
ornicar
575b75a9df [DependencyInjection] Fix fixture class loaded twice during dumper tests 2011-02-05 20:27:47 +01:00
Fabien Potencier
199e6bf893 [BrowserKit] removed annotation in a unit test to fix coverage 2011-02-05 16:02:59 +01:00
Martijn Evers
1e3dc1479c [Testing][HttpKernel] Added possibility to functional test raw body data 2011-02-04 13:07:13 +01:00
Victor Berchet
3ed47114d6 [Bundle] Make getPath() less error prone by allowing both backward and forward slashes 2011-02-04 12:12:19 +01:00
Bernhard Schussek
2276b98fc1 [Form] Fixed: ChoiceFields never validated 2011-02-04 11:30:49 +01:00
Daniel Holmes
f4282eea98 [Routing] added support for non-standard port numbers in absolute urls 2011-02-04 00:25:25 +01:00
Fabien Potencier
b6f400a2bc [DependencyInjection] made an optimization on dumped DIC
When dumping a Container, and if it is frozen, we use a plain
PHP array for parameters instead of a ParameterBag.
2011-02-04 00:17:51 +01:00
Bernhard Schussek
a725415440 [Form] Fixed RepeatedField not to trigger NotNull/NotBlank errors if any of the fields was filled in 2011-02-03 13:28:29 +01:00
Bernhard Schussek
39c148197f [Form] Fixed form validation
Separated validation of data and form had serious drawbacks. When a form had nested form whose data was not connected to the data of the root form, this data would not be validated.

The new implementation validates the whole object graph at once. Class Form has a new method validateData(), that manually passes the data to the GraphWalker of the Validator and overrides the Default group with the groups set in the form.
2011-02-03 13:21:44 +01:00
Bernhard Schussek
1a34743990 [Validator] Fixed: Collections annotated with @Valid may contain scalar values. These values are ignored by the GraphWalker 2011-02-03 13:21:37 +01:00
Bernhard Schussek
50955a3919 [Validator] Fixed PropertyPath to read array indices with special characters 2011-02-03 11:28:51 +01:00
Bernhard Schussek
5ed4d91bb8 [Validator] Implemented Execute constraint 2011-02-03 11:00:03 +01:00
Bernhard Schussek
7c9c7af863 [Form] Fixed arrays not to be passed to the validator 2011-02-02 17:32:24 +01:00
Bernhard Schussek
5e3fab214e [Form] The form is now validated seperatedly from its data. The form is validated in group "Default", the data in the group set in option "validation_groups" 2011-02-02 15:25:05 +01:00
Bernhard Schussek
c923af2879 [Form] Adapted constructor of CollectionField to match the constructors of the other fields. The field prototype is now optional. 2011-02-02 14:46:33 +01:00
Bernhard Schussek
4f0283a508 [Form] Removed Form::isBound(). Form::bind() is only a shortcut method now, use Form::isSubmitted() if you want to find out whether a form was submitted. 2011-02-02 14:46:33 +01:00
Bernhard Schussek
628a4d1fd8 [Form] Refactored validation logic into validate() method. Removed bindGlobals() to reduce API clutter 2011-02-02 14:46:33 +01:00
Thomas
e6dc155e89 fix validator class metadata warning 2011-02-02 11:37:41 +01:00
Jeremy Mikola
4e0db56810 [Form] Fix getValidator() to reference the "validator" option instead of property 2011-02-02 11:34:18 +01:00
Johannes Schmitt
b484763a7a [DependencyInjection] added first version of the config normalizer
This is mainly intended for complex configurations to ease the work you
have with normalizing different configuration formats (YAML, XML, and PHP).

First, you have to set-up a config tree:

    $treeBuilder = new TreeBuilder();
    $tree = $treeBuilder
        ->root('security_config', 'array')
            ->node('access_denied_url', 'scalar')->end()
            ->normalize('encoder')
            ->node('encoders', 'array')
                ->key('class')
                ->prototype('array')
                    ->before()->ifString()->then(function($v) { return array('algorithm' => $v); })->end()
                    ->node('algorithm', 'scalar')->end()
                    ->node('encode_as_base64', 'scalar')->end()
                    ->node('iterations', 'scalar')->end()
                ->end()
            ->end()
        ->end()
        ->buildTree()
    ;

This tree and the metadata attached to the different nodes is then used
to intelligently transform the passed config array:

    $normalizedConfig = $tree->normalize($config);
2011-02-01 16:07:04 +01:00
Bernhard Schussek
a28151a8af [Form] Removed FormFactory and improved the form instantiation process
With the form factory there was no reasonable way to implement instantiation of custom form classes. So the implementation was changed to let the classes instantiate themselves. A FormContext instance with default settings has to be passed to the creation method. This context is by default configured in the DI container.

	$context = $this->get('form.context');
	// or
	$context = FormContext::buildDefault();
	$form = MyFormClass::create($context, 'author');

If you want to circumvent this process, you can also create a form manually. Remember that the services stored in the default context won't be available then unless you pass them explicitely.

	$form = new MyFormClass('author');
2011-02-01 15:27:12 +01:00
Bernhard Schussek
fb1f99137d [Form] Changed semantics of a "bound" form
A form now always has to be bound, independent of whether the request is a POST request or not. The bind() method detects itself whether the request was a post request or not and reads its data accordingly. The "old" bind()/isBound() methods were renamed to submit()/isSubmitted().

	$form = new Form('author');
	$form->bind($request, $author);

	if ($form->isValid()) {
		// isValid() implies isSubmitted(), non-submitted forms can
		// never be valid
		// do something with author now
	}

Alternatively, you can only bind global variables, if you don't have a request object.

	$form->bindGlobals($author);

Note that the $author object is in both cases optional. You can also pass no object at all and read the data using $form->getData(), but then no validation will occur. You can also prefill the form with an object during instantiation.

	$form = new Form('author', array('data' => $author));
	$form->bind($request);

	// etc.
2011-02-01 15:27:12 +01:00
Bernhard Schussek
e5ed98c324 [Form] Added option 'data' to Field for populating a field with a fixed value 2011-02-01 15:27:12 +01:00
Bernhard Schussek
fdbc064f06 [Form] Removed automatic distribution of the locale in the Form component. This leads to more problems than it solves. 2011-02-01 15:27:12 +01:00
Bernhard Schussek
c468db5c5b [Form] Merged classes FieldGroup and Form for simplicity 2011-02-01 15:27:12 +01:00
Bernhard Schussek
4fcb98547c [Form] Simplified Form::bind(), added convenience methods Form::bindRequest() and Form::bindGlobals() 2011-02-01 15:27:12 +01:00
Bernhard Schussek
57cbd57265 [Form] Fields may now be anonymous, but anonymous fields must not be added to groups. They can only be used as prototypes 2011-02-01 15:27:12 +01:00
Bernhard Schussek
d152b5e265 [Form] Moved Doctrine2 specific files 2011-02-01 15:27:12 +01:00
Bernhard Schussek
347c069e8d [DoctrineBundle][Form] Implemented EntityChoiceField 2011-02-01 15:27:12 +01:00
Fabien Potencier
2c4355460e [HttpKernel] added a StoreInterface 2011-01-31 14:15:12 +01:00
Victor Berchet
f470c5605e [Request] Fix getting mime type 2011-01-30 20:14:40 +01:00
Jordi Boggiano
571c984625 [Validator] Skip tests that rely on Doctrine being present if its not 2011-01-30 09:18:18 +01:00