<p dir="auto">I'm trying to setup something like this with Symfony 2.6.1:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$builder
    -&gt;add('field', 'choice', [
        'choices' =&gt; array_combine(range(0.1, 1.0, 0.1), range(0.1, 1.0, 0.1))
    ]);"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>builder</span>
    -&gt;<span class="pl-en">add</span>(<span class="pl-s">'field'</span>, <span class="pl-s">'choice'</span>, [
        <span class="pl-s">'choices'</span> =&gt; array_combine(range(<span class="pl-c1">0.1</span>, <span class="pl-c1">1.0</span>, <span class="pl-c1">0.1</span>), range(<span class="pl-c1">0.1</span>, <span class="pl-c1">1.0</span>, <span class="pl-c1">0.1</span>))
    ]);</pre></div>
<p dir="auto">and this is the mapping for Doctrine:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    field:
        type: decimal
        precision: 2
        scale: 1
        options:
            default: 1.0"><pre class="notranslate">    <span class="pl-ent">field</span>:
        <span class="pl-ent">type</span>: <span class="pl-s">decimal</span>
        <span class="pl-ent">precision</span>: <span class="pl-c1">2</span>
        <span class="pl-ent">scale</span>: <span class="pl-c1">1</span>
        <span class="pl-ent">options</span>:
            <span class="pl-ent">default</span>: <span class="pl-c1">1.0</span></pre></div>
<p dir="auto">The field never shows the value 1.0 as selected when it is (works fine for 0.1 =&gt; 0.9). I have tried converting all float values to string using <code class="notranslate">number_format</code> but doesn't work either.</p>
<p dir="auto">I have also tried using <code class="notranslate">http://symfony.com/doc/current/reference/forms/types/choice.html#choice-list</code>, but taking the example on that page I get this:</p>
<div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;select&gt;
   &lt;option value=&quot;0&quot;&gt;Full&lt;/option&gt;
   &lt;option value=&quot;1&quot;&gt;Half&lt;/option&gt;
&lt;/select&gt;"><pre class="notranslate"><span class="pl-kos">&lt;</span><span class="pl-ent">select</span><span class="pl-kos">&gt;</span>
   <span class="pl-kos">&lt;</span><span class="pl-ent">option</span> <span class="pl-c1">value</span>="<span class="pl-s">0</span>"<span class="pl-kos">&gt;</span>Full<span class="pl-kos">&lt;/</span><span class="pl-ent">option</span><span class="pl-kos">&gt;</span>
   <span class="pl-kos">&lt;</span><span class="pl-ent">option</span> <span class="pl-c1">value</span>="<span class="pl-s">1</span>"<span class="pl-kos">&gt;</span>Half<span class="pl-kos">&lt;/</span><span class="pl-ent">option</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">&lt;/</span><span class="pl-ent">select</span><span class="pl-kos">&gt;</span></pre></div>
<p dir="auto">as you can see, there's no float values here (shouldn't it be 1 =&gt; Full, 0.5 =&gt; Half?) Is this a bug with <code class="notranslate">ChoiceList</code> or the example is incorrect?</p>
<p dir="auto">Thanks in advanced for any insight.</p>
<p dir="auto"><strong>Description</strong><br>
The idea of this feature lies on the following <a href="https://www.owasp.org/index.php/REST_Security_Cheat_Sheet#Input_validation" rel="nofollow">OWASP recommendation</a>:</p>
<blockquote>
<p dir="auto">Define an appropriate request size limit and reject requests exceeding the limit with HTTP response status 413 Request Entity Too Large</p>
</blockquote>
<p dir="auto">After <a href="https://github.com/api-platform/api-platform/issues/680" data-hovercard-type="issue" data-hovercard-url="/api-platform/api-platform/issues/680/hovercard">discussion</a> with <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/dunglas/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/dunglas">@dunglas</a> about implementing this feature in the api-platform project, the subject of implementing it directly in Symfony has been brought.</p>
<p dir="auto">In my opinion, this feature makes sense in, but is not limited to, a Rest API context, so it'd make sense to implement it in the Symfony HttpKernel component. However, one could argue that this is a security related feature that should live in the Security component.</p>
<p dir="auto">The implementation would rely on a <code class="notranslate">kernel.request</code> event listener configured with a request content max size (defaulting to <code class="notranslate">ini_get('post_max_size')</code>). Comparison would then be performed against the <code class="notranslate">Content-Length</code> request header. <a href="https://gist.github.com/gquemener/bbab91389e0d4656bc6c4c832618e4c5">Here's a gist showing how it could look like</a>.</p>
<p dir="auto">The fact is that it must be implemented smartly in order not to conflict with the existing handling of request size exceeding in the <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php#L71">Symfony Form component</a>.</p>
<p dir="auto">This feature could be disabled by default, for example.<br>
It could be enablable on a global scope, on a route scope, on a pattern scope, ... The choices are quite wide.</p>
<p dir="auto">Unlike how it's made in the Symfony Form component, I believe it makes sense to perform this check no matter which HTTP method is used.</p>
<p dir="auto">Finally, unless duplicating <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Util/ServerParams.php">this logic</a> in the component which would welcome this feature, we should think about how to extract it in a common package (maybe a new <code class="notranslate">php-directive</code> package which would perform <code class="notranslate">ini_get</code> calls and <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Util/ServerParams.php#L46-L74">value normalizations</a>).</p>
<p dir="auto">Thank you for your time and sharing thoughts about this,<br>
Regards.</p>

<p dir="auto"><strong>Example</strong></p>
<p dir="auto">Enabling globaly</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="framework:
    prevent_content_length_exceeding: true
    max_content_length: 10M"><pre class="notranslate"><span class="pl-ent">framework</span>:
    <span class="pl-ent">prevent_content_length_exceeding</span>: <span class="pl-c1">true</span>
    <span class="pl-ent">max_content_length</span>: <span class="pl-c1">10M</span></pre></div>
<p dir="auto">Enabling on a route</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="routes:
    index:
        path: /
        prevent_content_length_exceeding: true
        max_content_length: 10M"><pre class="notranslate"><span class="pl-ent">routes</span>:
    <span class="pl-ent">index</span>:
        <span class="pl-ent">path</span>: <span class="pl-s">/</span>
        <span class="pl-ent">prevent_content_length_exceeding</span>: <span class="pl-c1">true</span>
        <span class="pl-ent">max_content_length</span>: <span class="pl-c1">10M</span></pre></div>