Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[Form] Implemented form debugger #9082

Merged
merged 5 commits into from

14 participants

Bernhard Schussek Fabien Potencier Hugo Hamon Robert Schönthal hacfi Sylvain Mauduit Mickaël Andrieu Leevi Graham Peter Bowyer Almog Baku Christophe Coevoet Arnaud Kleinpeter Michel Salib Timothée Barray
Bernhard Schussek
Collaborator

Same as #9021 (kudos to @digitalkaoz!), with some added caramel.

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Note: Please keep in mind that this is a first version only. Not all features (especially UX/UI-wise) that I'd like to see are in there, but it's good enough for a first merge.

Fabien Potencier
Owner

@bschussek Can you add some screenshots here?

Bernhard Schussek
Collaborator

Here you go :)

Toolbar:
form-debugger-1

Profiler:
form-debugger-2

Hugo Hamon

Killer feature! Thanks for this!

.../Component/HttpKernel/DataCollector/DataCollector.php
((14 lines not shown))
*/
abstract class DataCollector implements DataCollectorInterface, \Serializable
{
protected $data;
+ /**
+ * @var ValueExporterInterface
+ */
+ protected $valueExporter;
+
+ public function __construct(ValueExporterInterface $valueExporter = null)
Fabien Potencier Owner
fabpot added a note

That's a big BC break for any DataCollector out there.

Bernhard Schussek Collaborator

Why? It's got a default value.

Fabien Potencier Owner
fabpot added a note

sorry, didn't see the default value.

Christophe Coevoet Collaborator
stof added a note

@bschussek But any collector out there must now call the parent constructor if they have their own constructor, otherwise the exporter is not set

Bernhard Schussek Collaborator

@stof Check the body of the method.. ;)

Christophe Coevoet Collaborator
stof added a note

If existing collectors have a custom constructor, they need to update their code. Otherwise the body of the method is not executed.

And existing collectors are not calling parent::__construct() currently as there is no parent constructor.

Bernhard Schussek Collaborator

Good point, I will fix this.

Bernhard Schussek Collaborator

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Deleted user

OMG! +1000 ;)

...pKernel/DataCollector/Util/ValueExporterInterface.php
((4 lines not shown))
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\DataCollector\Util;
+
+/**
+ * Converts PHP values into strings.
+ *
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+interface ValueExporterInterface
Fabien Potencier Owner
fabpot added a note

Why do we need an interface here?

Bernhard Schussek Collaborator

Because it's a service and other classes depend on it. Dependencies to services should always be coded against interfaces.

Fabien Potencier Owner
fabpot added a note

For me, we need an interface only if we can have different implementations. If not, I don't see the point.

Bernhard Schussek Collaborator

We're a framework. We should follow best practices consistently, not on a case-by-case basis, because our users will do a lot of stuff with our code that we can't foresee.

Bernhard Schussek Collaborator

And for someone it might make sense to have an alternative implementation here.

Fabien Potencier Owner
fabpot added a note

Which best practice are you talking about?

I think the practice here is Open/Close principle which says "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification" (cf. wikipedia). So yes it is good to allow safe extension via interfaces.
But we should keep in mind that we want to keep a clear/simple exposure of the architecture of the components (ie. the interfaces). Interfaces lead the developer on how he should override services. IMO exposing to much is not always good. It would allow unnecessary overrides that might denote a bad practice. That is the Close part of the principle.

Arnaud Kleinpeter
nanocom added a note

I don't see the point of an interface here either, seems overcomplicated to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Robert Schönthal

I dont See the need for a formdatacollectorinterface. But the Rest looks great. I like the idea of the proxy type :) +1 from me

...ihatewritingonphones

hacfi

@digitalkaoz Thanks for the hard work..I love it ;)

Sylvain Mauduit

Thanks @bschussek & @digitalkaoz for this feature. It will definitely be very useful.

Is there a way to somehow display constraints linked to fields in the profiler? And highlight the invalid fields which doesn't match the constraints?

Mickaël Andrieu

Sounds Great !!! Available for 2.4 I hope ? :)

Peter Bowyer

@bschussek What would you like to achieve UX/UI-wise?

Bernhard Schussek
Collaborator

@pbowyer I'll open a new ticket for that.

Bernhard Schussek
Collaborator
...onent/HttpKernel/DataCollector/Util/ValueExporter.php
((5 lines not shown))
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\DataCollector\Util;
+
+/**
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+class ValueExporter
+{
+ /**
+ * {@inheritdoc}
Fabien Potencier Owner
fabpot added a note

You cannot use @inheritdoc anymore ;)

Bernhard Schussek Collaborator

Really, why? More info about that?

Christophe Coevoet Collaborator
stof added a note

Where are you inheriting it from ? There is no parent anymore

Bernhard Schussek Collaborator

Ooops. I thought you meant that we changed our conventions :) will fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
.../Component/HttpKernel/DataCollector/DataCollector.php
((19 lines not shown))
- }
-
- if (null === $var) {
- return 'null';
- }
-
- if (false === $var) {
- return 'false';
- }
-
- if (true === $var) {
- return 'true';
- }
+ if (null === $this->valueExporter) {
+ $this->valueExporter = new ValueExporter();
+ }
Fabien Potencier Owner
fabpot added a note

indent issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
.../Component/HttpKernel/DataCollector/DataCollector.php
((14 lines not shown))
*/
abstract class DataCollector implements DataCollectorInterface, \Serializable
{
protected $data;
+ /**
+ * @var ValueExporter
+ */
+ private $valueExporter;
+
Fabien Potencier Owner
fabpot added a note

indent issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Bernhard Schussek
Collaborator

The inheritdoc issue is fixed.

Fabien Potencier fabpot referenced this pull request from a commit
Fabien Potencier fabpot merged branch bschussek/form-debugger (PR #9082)
This PR was merged into the master branch.

Discussion
----------

[Form] Implemented form debugger

Same as #9021 (kudos to @digitalkaoz!), with some added caramel.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

**Note:** Please keep in mind that this is a first version only. Not all features (especially UX/UI-wise) that I'd like to see are in there, but it's good enough for a first merge.

Commits
-------

89509d9 [Form] Improved form debugger
f56c577 [HttpKernel] Extracted value exporting logic of DataCollector into a separate ValueExporter class
56d78ed [Form] Decoupled methods of ResolvedFormType so that they can be overridden individually by decorators
a994a5d [Form] Merged subsriber/collector, also collect valid forms
1972a91 [Form] Added form debug collector
55de9d9
Fabien Potencier fabpot merged commit 89509d9 into from
Timothée Barray

If form config is not enabled, this line will break as it use %form.resolved_type_factory.class% parameter, defined in form.xml.

So I guess we should load it, only if form config is neabled.

edit : Here is a PR : #9137

Almog Baku

This is big! +1000 for this genius feature~!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 25, 2013
  1. Robert Schönthal Bernhard Schussek

    [Form] Added form debug collector

    digitalkaoz authored webmozart committed
  2. Robert Schönthal Bernhard Schussek
  3. Bernhard Schussek

    [Form] Decoupled methods of ResolvedFormType so that they can be over…

    webmozart authored
    …ridden individually by decorators
  4. Bernhard Schussek

    [HttpKernel] Extracted value exporting logic of DataCollector into a …

    webmozart authored
    …separate ValueExporter class
  5. Bernhard Schussek
Something went wrong with that request. Please try again.