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

Skip to content

Extract the profiler to a new component #14763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Monolog/Handler/DebugHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function getLogs()
'priority' => $record['level'],
'priorityName' => $record['level_name'],
'context' => $record['context'],
'channel' => isset($record['channel']) ? $record['channel'] : '',
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@

{%- block widget_attributes -%}
id="{{ id }}" name="{{ full_name }}"
{%- if read_only %} readonly="readonly"{% endif -%}
{%- if disabled %} disabled="disabled"{% endif -%}
{%- if required %} required="required"{% endif -%}
{%- for attrname, attrvalue in attr -%}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"symfony/phpunit-bridge": "~2.7|~3.0.0",
"symfony/asset": "~2.7|~3.0.0",
"symfony/finder": "~2.3|~3.0.0",
"symfony/form": "~2.7|~3.0.0",
"symfony/form": "~2.8|~3.0.0",
"symfony/http-kernel": "~2.3|~3.0.0",
"symfony/intl": "~2.3|~3.0.0",
"symfony/routing": "~2.2|~3.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>" <?php if ($read_only): ?>readonly="readonly" <?php endif ?>
<?php if ($disabled): ?>disabled="disabled" <?php endif ?>
<?php if ($required): ?>required="required" <?php endif ?>
id="<?php echo $view->escape($id) ?>" name="<?php echo $view->escape($full_name) ?>"<?php if ($disabled): ?> disabled="disabled"<?php endif ?>
<?php if ($required): ?> required="required"<?php endif ?>
<?php foreach ($attr as $k => $v): ?>
<?php if (in_array($k, array('placeholder', 'title'), true)): ?>
<?php printf('%s="%s" ', $view->escape($k), $view->escape($view['translator']->trans($v, array(), $translation_domain))) ?>
<?php printf(' %s="%s"', $view->escape($k), $view->escape($view['translator']->trans($v, array(), $translation_domain))) ?>
<?php elseif ($v === true): ?>
<?php printf('%s="%s" ', $view->escape($k), $view->escape($k)) ?>
<?php printf(' %s="%s"', $view->escape($k), $view->escape($k)) ?>
<?php elseif ($v !== false): ?>
<?php printf('%s="%s" ', $view->escape($k), $view->escape($v)) ?>
<?php printf(' %s="%s"', $view->escape($k), $view->escape($v)) ?>
<?php endif ?>
<?php endforeach ?>
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"symfony/finder": "~2.0,>=2.0.5|~3.0.0",
"symfony/intl": "~2.3|~3.0.0",
"symfony/security": "~2.6|~3.0.0",
"symfony/form": "~2.7|~3.0.0",
"symfony/form": "~2.8|~3.0.0",
"symfony/class-loader": "~2.1|~3.0.0",
"symfony/expression-language": "~2.6|~3.0.0",
"symfony/process": "~2.0,>=2.0.5|~3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,30 @@
</table>

{% if collector.logs %}
<ul class="alt">
<table>
<tr>
<th>#</th>
<th>Priority</th>
<th>Channel</th>
<th>Message and context</th>
</tr>

{% set log_loop_index = 0 %}
{% for log in collector.logs %}
{% set is_deprecation = log.context.level is defined and log.context.type is defined and (constant('E_DEPRECATED') == log.context.type or constant('E_USER_DEPRECATED') == log.context.type) %}
{% if priority == '-100' ? is_deprecation : log.priority >= priority %}
{% set log_loop_index = log_loop_index + 1 %}
<li class="{{ cycle(['odd', 'even'], log_loop_index) }}{% if log.context.scream is defined %} scream{% elseif log.priority >= 400 %} error{% elseif log.priority >= 300 or is_deprecation %} warning{% endif %}">
{{ logger.display_message(loop.index, log, is_deprecation) }}
</li>
<tr class="{{ cycle(['odd', 'even'], log_loop_index) }}{% if log.context.scream is defined %} scream{% elseif log.priority >= 400 %} error{% elseif log.priority >= 300 or is_deprecation %} warning{% endif %}">
<td>{{ log_loop_index }}</td>
<td>{{ is_deprecation ? 'DEPRECATION' : log.priorityName }}</td>
<td>{{ log.channel is defined ? log.channel }}</td>
<td>{{ logger.display_message(loop.index, log, is_deprecation) }}</td>
</tr>
{% endif %}
{% else %}
<li><em>No logs available for this priority.</em></li>
<tr><td colspan="4"><em>No logs available for {{ priority }} priority.</em></td></tr>
{% endfor %}
</ul>
</table>
{% else %}
<p>
<em>No logs available.</em>
Expand All @@ -114,7 +124,7 @@
{% set stack = log.context.stack|default([]) %}
{% set id = 'sf-call-stack-' ~ log_index %}

DEPRECATED - {{ log.message }}
{{ log.message }}

{% if stack %}
<a href="#" onclick="Sfjs.toggle('{{ id }}', document.getElementById('{{ id }}-on'), document.getElementById('{{ id }}-off')); return false;">
Expand Down Expand Up @@ -144,7 +154,7 @@
{% endif %}
{% endfor %}
{% else %}
{{ log.priorityName }} - {{ log.message }}
{{ log.message }}
{% if log.context is defined and log.context is not empty %}
<br />
<small>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pre, code {
width: 250px;
margin-left: -100%;
}
#collector-content table td {
table td {
background-color: white;
}
h1 {
Expand Down Expand Up @@ -273,15 +273,15 @@ ul.alt li {
ul.alt li.even {
background: #f1f7e2;
}
ul.alt li.error {
ul.alt li.error, tr.error td {
background-color: #f66;
margin-bottom: 1px;
}
ul.alt li.warning {
ul.alt li.warning, tr.warning td {
background-color: #ffcc00;
margin-bottom: 1px;
}
ul.alt li.scream, ul.alt li.scream strong {
ul.alt li.scream, ul.alt li.scream strong, tr.scream td, tr.scream strong {
color: gray;
}
ul.sf-call-stack li {
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

2.8.0
-----

* deprecated option "read_only" in favor of "attr['readonly']"

2.7.0
-----

Expand Down
31 changes: 26 additions & 5 deletions src/Symfony/Component/Form/Extension/Core/Type/FormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,20 @@ public function buildView(FormView $view, FormInterface $form, array $options)
parent::buildView($view, $form, $options);

$name = $form->getName();
$readOnly = $options['read_only'];

if ($view->parent) {
if ('' === $name) {
throw new LogicException('Form node with empty name can be used only as root form node.');
}

// Complex fields are read-only if they themselves or their parents are.
if (!$readOnly) {
$readOnly = $view->parent->vars['read_only'];
if (!isset($view->vars['attr']['readonly']) && isset($view->parent->vars['attr']['readonly']) && false !== $view->parent->vars['attr']['readonly']) {
$view->vars['attr']['readonly'] = true;
}
}

$view->vars = array_replace($view->vars, array(
'read_only' => $readOnly,
'read_only' => isset($view->vars['attr']['readonly']) && false !== $view->vars['attr']['readonly'], // deprecated
'errors' => $form->getErrors(),
'valid' => $form->isSubmitted() ? $form->isValid() : true,
'value' => $form->getViewData(),
Expand Down Expand Up @@ -185,12 +184,31 @@ public function configureOptions(OptionsResolver $resolver)
return $attributes;
};

// BC for "read_only" option
$attrNormalizer = function (Options $options, array $attr) {
if (!isset($attr['readonly']) && $options['read_only']) {
$attr['readonly'] = true;
}

return $attr;
};

$readOnlyNormalizer = function (Options $options, $readOnly) {
if (null !== $readOnly) {
trigger_error('The form option "read_only" is deprecated since version 2.8 and will be removed in 3.0. Use "attr[\'readonly\']" instead.', E_USER_DEPRECATED);

return $readOnly;
}

return false;
};

$resolver->setDefaults(array(
'data_class' => $dataClass,
'empty_data' => $emptyData,
'trim' => true,
'required' => true,
'read_only' => false,
'read_only' => null, // deprecated
'max_length' => null,
'pattern' => null,
'property_path' => null,
Expand All @@ -209,6 +227,9 @@ public function configureOptions(OptionsResolver $resolver)
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
));

$resolver->setNormalizer('attr', $attrNormalizer);
$resolver->setNormalizer('read_only', $readOnlyNormalizer);

$resolver->setAllowedTypes('label_attr', 'array');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,10 @@ public function testHidden()
);
}

public function testReadOnly()
/**
* @group legacy
*/
public function testLegacyReadOnly()
{
$form = $this->factory->createNamed('name', 'text', null, array(
'read_only' => true,
Expand Down Expand Up @@ -1907,14 +1910,13 @@ public function testWidgetAttributes()
$form = $this->factory->createNamed('text', 'text', 'value', array(
'required' => true,
'disabled' => true,
'read_only' => true,
'attr' => array('maxlength' => 10, 'pattern' => '\d+', 'class' => 'foobar', 'data-foo' => 'bar'),
'attr' => array('readonly' => true, 'maxlength' => 10, 'pattern' => '\d+', 'class' => 'foobar', 'data-foo' => 'bar'),
));

$html = $this->renderWidget($form->createView());

// compare plain HTML to check the whitespace
$this->assertSame('<input type="text" id="text" name="text" readonly="readonly" disabled="disabled" required="required" maxlength="10" pattern="\d+" class="foobar form-control" data-foo="bar" value="value" />', $html);
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar form-control" data-foo="bar" value="value" />', $html);
}

public function testWidgetAttributeNameRepeatedIfTrue()
Expand Down
10 changes: 6 additions & 4 deletions src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,10 @@ public function testHidden()
);
}

public function testReadOnly()
/**
* @group legacy
*/
public function testLegacyReadOnly()
{
$form = $this->factory->createNamed('name', 'text', null, array(
'read_only' => true,
Expand Down Expand Up @@ -2119,14 +2122,13 @@ public function testWidgetAttributes()
$form = $this->factory->createNamed('text', 'text', 'value', array(
'required' => true,
'disabled' => true,
'read_only' => true,
'attr' => array('maxlength' => 10, 'pattern' => '\d+', 'class' => 'foobar', 'data-foo' => 'bar'),
'attr' => array('readonly' => true, 'maxlength' => 10, 'pattern' => '\d+', 'class' => 'foobar', 'data-foo' => 'bar'),
));

$html = $this->renderWidget($form->createView());

// compare plain HTML to check the whitespace
$this->assertSame('<input type="text" id="text" name="text" readonly="readonly" disabled="disabled" required="required" maxlength="10" pattern="\d+" class="foobar" data-foo="bar" value="value" />', $html);
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar" data-foo="bar" value="value" />', $html);
}

public function testWidgetAttributeNameRepeatedIfTrue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ public function testSubmittedDataIsNotTrimmedBeforeTransformingIfNoTrimming()
$this->assertEquals('reverse[ a ]', $form->getData());
}

public function testNonReadOnlyFormWithReadOnlyParentIsReadOnly()
/**
* @group legacy
*/
public function testLegacyNonReadOnlyFormWithReadOnlyParentIsReadOnly()
{
$view = $this->factory->createNamedBuilder('parent', 'form', null, array('read_only' => true))
->add('child', 'form')
Expand All @@ -109,7 +112,20 @@ public function testNonReadOnlyFormWithReadOnlyParentIsReadOnly()
$this->assertTrue($view['child']->vars['read_only']);
}

public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly()
public function testNonReadOnlyFormWithReadOnlyParentIsReadOnly()
{
$view = $this->factory->createNamedBuilder('parent', 'form', null, array('attr' => array('readonly' => true)))
->add('child', 'form')
->getForm()
->createView();

$this->assertTrue($view['child']->vars['attr']['readonly']);
}

/**
* @group legacy
*/
public function testLegacyReadOnlyFormWithNonReadOnlyParentIsReadOnly()
{
$view = $this->factory->createNamedBuilder('parent', 'form')
->add('child', 'form', array('read_only' => true))
Expand All @@ -119,7 +135,20 @@ public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly()
$this->assertTrue($view['child']->vars['read_only']);
}

public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
public function testReadOnlyFormWithNonReadOnlyParentIsReadOnly()
{
$view = $this->factory->createNamedBuilder('parent', 'form')
->add('child', 'form', array('attr' => array('readonly' => true)))
->getForm()
->createView();

$this->assertTrue($view['child']->vars['attr']['readonly']);
}

/**
* @group legacy
*/
public function testLegacyNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
{
$view = $this->factory->createNamedBuilder('parent', 'form')
->add('child', 'form')
Expand All @@ -129,6 +158,16 @@ public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
$this->assertFalse($view['child']->vars['read_only']);
}

public function testNonReadOnlyFormWithNonReadOnlyParentIsNotReadOnly()
{
$view = $this->factory->createNamedBuilder('parent', 'form')
->add('child', 'form')
->getForm()
->createView();

$this->assertArrayNotHasKey('readonly', $view['child']->vars['attr']);
}

public function testPassMaxLengthToView()
{
$form = $this->factory->create('form', null, array('attr' => array('maxlength' => 10)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* ConfigDataCollector.
*
* @author Fabien Potencier <[email protected]>
*
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\ConfigDataCollector instead.
*/
class ConfigDataCollector extends DataCollector
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\DataCollector;

use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
use Symfony\Component\Profiler\DataCollector\AbstractDataCollector;

/**
* DataCollector.
Expand All @@ -20,8 +21,10 @@
*
* @author Fabien Potencier <[email protected]>
* @author Bernhard Schussek <[email protected]>
*
* @deprecated since 2.8, to be removed in 3.0. Use Symfony\Component\Profiler\DataCollector\AbstractDataCollector instead.
*/
abstract class DataCollector implements DataCollectorInterface, \Serializable
abstract class DataCollector extends AbstractDataCollector implements DataCollectorInterface, \Serializable
{
protected $data = array();

Expand Down
Loading