8000 Add support for optional path argument in DebugDcaCommand by Tastaturberuf · Pull Request #8357 · contao/contao · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for optional path argument in DebugDcaCommand #8357

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

Open
wants to merge 4 commits into
base: 5.x
Choose a base branch
from

Conversation

Tastaturberuf
Copy link
Contributor

The DebugDcaCommand now allows specifying a path to dump specific parts of the DCA configuration. This enhances debugging flexibility by enabling targeted output of nested DCA structures. An exception is thrown for invalid paths to ensure robust error handling.

Now you can use something like:

php bin/console debug:dca tl_member config         
array:7 [
  "dataContainer" => "Contao\DC_Table"
  "enableVersioning" => true
  "onsubmit_callback" => array:1 [
    0 => array:2 [
      0 => "tl_member"
      1 => "storeDateAdded"
    ]
  ]
  "sql" => array:1 [
    "keys" => array:5 [
      "id" => "primary"
      "tstamp" => "index"
      "username" => "unique"
      "email" => "index"
      "login,disable,start,stop" => "index"
    ]
  ]
  "onload_callback" => array:1 [
    0 => array:2 [
      0 => "Contao\Newsletter"
      1 => "updateAccount"
    ]
  ]
  "ondelete_callback" => array:1 [
    0 => array:2 [
      0 => "contao.listener.data_container.record_preview"
      1 => "storePrecompiledRecordPreview"
    ]
  ]
  "onbeforesubmit_callback" => array:3 [
    0 => array:2 [
      0 => "contao.listener.data_container.start_stop_validation"                                                                                                                                                    
      1 => "__invoke"                                                                                                                                                                                                
    ]                                                                                                                                                                                                                
    1 => array:2 [                                                                                                                                                                                                   
      0 => "contao_news.listener.data_container.start_stop_validation"                                                                                                                                               
      1 => "__invoke"                                                                                                                                                                                                
    ]                                                                                                                                                                                                                
    2 => array:2 [                                                                                                                                                                                                   
      0 => "contao_calendar.listener.data_container.start_stop_validation"                                                                                                                                           
      1 => "__invoke"                                                                                                                                                                                                
    ]                                                                                                                                                                                                                
  ]                                                                                                                                                                                                                  
]

You can go further is you add more keys:

php bin/console debug:dca tl_member config sql keys
array:5 [
  "id" => "primary"                                                                                                                                                                                                  
  "tstamp" => "index"                                                                                                                                                                                                
  "username" => "unique"                                                                                                                                                                                             
  "email" => "index"                                                                                                                                                                                                 
  "login,disable,start,stop" => "index"                                                                                                                                                                              
]

If the path is not available an exception is thrown:

php bin/console debug:dca tl_member config sql keys impossible
13:54:24 CRITICAL  [console] Error thrown while running command "debug:dca tl_member config sql keys impossible". Message: "Invalid path: impossible" ["exception" => Symfony\Component\Console\Exception\InvalidArgumentException { …},"command" => "debug:dca tl_member config sql keys impossible","message" => "Invalid path: impossible"]                                                                                            

                            
  Invalid path: impossible  
                            

debug:dca <table> [<path>...]

The DebugDcaCommand now allows specifying a path to dump specific parts of the DCA configuration. This enhances debugging flexibility by enabling targeted output of nested DCA structures. An exception is thrown for invalid paths to ensure robust error handling.
@m-vo
Copy link
Member
m-vo commented May 16, 2025

Nice! ❤️ I would also want this for all the other tree-shaped debug outputs. 🙂

IMHO children in the path should use a dot notation(debug:dca tl_member config.sql.keys) similar to how JsonPath does it (or maybe even use the respective Symfony component for that?).

@Tastaturberuf
Copy link
Contributor Author
Tastaturberuf commented May 16, 2025

Iam not sure if there is an dot notation component. in my projects I use https://github.com/adbario/php-dot-notation. but i dont want to add a new dependency.

There is https://symfony.com/doc/current/components/property_access.html#reading-from-arrays but the syntax is different.

php bin/console debug:dca tl_member [config][sql][keys]
array:5 [
  "id" => "primary"                                                                                                                                                                                                  
  "tstamp" => "index"                                                                                                                                                                                                
  "username" => "unique"                                                                                                                                                                                             
  "email" => "index"                                                                                                                                                                                                 
  "login,disable,start,stop" => "index"                                                                                                                                                                              
]

@aschempp
Copy link
Member
aschempp commented May 16, 2025

IMHO children in the path should use a dot notation(debug:dca tl_member config.sql.keys)

I think so too. Just split the string by dot and use the parts imho. We do that everywhere (e.g. for registering callbacks), so actually having a dot in e.g. a field name is not really supported anyway.

@Tastaturberuf
Copy link
Contributor Author
Tastaturberuf commented May 16, 2025

If we need this in multiple classes se can create a new array helper. Maybe we copy mostly from this class

https://github.com/adbario/php-dot-notation/blob/3.x/src/Dot.php

Or we require this package.

@aschempp
Copy link
Member

A class that does explode('.', $value)?

@Tastaturberuf
Copy link
Contributor Author

no, a class that also runs through the array and finds errors. like my getArray-Method. We dont want to repeat that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0