Skip to content

[FrameworkBundle] Question when converting config/packages/routing.yaml to config/packages/routing.php #62200

@mickverm

Description

@mickverm

Symfony version(s) affected

7.4.0-BETA1

Description

I was trying out migrating the YAML config files to PHP files (see: #62129)

How to reproduce

When migrating config/packages/routing.yaml to config/packages/routing.php, PHPStan throws an error because it expects the router key to contains the resource key, but I'm unsure what to put there seeing as it was not present in the YAML config but worked anyway. Setting it to null does not work.

Before:

framework:
    router:
        # Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
        # See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
        #default_uri: http://localhost

when@prod:
    framework:
        router:
            strict_requirements: null

After:

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return App::config([
    'framework' => [
        // I had to comment this out
        // 'router' => [
        //     // Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
        //     // See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
        //     // 'default_uri' => 'http://localhost',
        // ],
    ],

    'when@prod' => [
        'framework' => [
            'router' => [
                'resource' => '????', // What do I put here?
                'strict_requirements' => null,
            ],
        ],
    ],
]);

resource is required according to:

->scalarNode('resource')->isRequired()->end()

Possible Solution

No response

Additional Context

PHPStan error:

 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   config\packages\routing.php
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  :7     Parameter #1 $config of static method Symfony\Component\DependencyInjection\Loader\Configurator\App::config() expects array{imports?: list<array{resource: string, type?: string|null, ignore_errors?: bool}|string>, parameters?: array<str  
         ing, array<array|bool|float|int|string|UnitEnum|null>|bool|float|int|string|UnitEnum|null>, services?: array{_defaults?: array{public?: bool, tags?: mixed, resource_tags?: mixed, autowire?: bool, autoconfigure?: bool, bind?: array<strin  
         g, mixed>}, _instanceof?: array{shared?: bool, lazy?: bool|string, public?: bool, properties?: array<string, mixed>, configurator?: array{string|Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator, string}|Cl  
         osure|string|Symfony\Component\DependencyInjection\Loader\Configurator\ExpressionConfigurator|Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator, calls?: list<array<0|1|2|string, array<int<0, max>|string,     
         mixed>|bool|string>>, tags?: mixed, resource_tags?: mixed, ...}}, doctrine?: array{dbal?: array{default_connection?: bool|float|int|string|null, types?: array<string, array{class: bool|float|int|string|null}|string>, driver_schemes?: ar  
         ray<string, bool|float|int|string|null>, connections?: array<string, array{url?: bool|float|int|string|null, dbname?: bool|float|int|string|null, host?: bool|float|int|string|null, port?: bool|float|int|string|null, user?: bool|float|in  
         t|string|null, password?: bool|float|int|string|null, dbname_suffix?: bool|float|int|string|null, application_name?: bool|float|int|string|null, ...}>}, orm?: array{default_entity_manager?: bool|float|int|string|null, enable_native_lazy  
         _objects?: bool, controller_resolver?: array{enabled?: bool, auto_mapping?: bool, evict_cache?: bool}|bool, entity_managers?: array<string, array{query_cache_driver?: array{type?: bool|float|int|string|null, id?:
         bool|float|int|string|null, pool?: bool|float|int|string|null}|string, metadata_cache_driver?: array{type?: bool|float|int|string|null, id?: bool|float|int|string|null, pool?: bool|float|int|string|null}|string, result_cache_driver?:     
         array{type?: bool|float|int|string|null, id?: bool|float|int|string|null, pool?: bool|float|int|string|null}|string, entity_listeners?: array{entities?: array<string, array{listeners?: array<string, array{events?: list<array{type?: bool  
         |float|int|string|null, method?: bool|float|int|string|null}>}>}>}, connection?: bool|float|int|string|null, class_metadata_factory_name?: bool|float|int|string|null, default_repository_class?: bool|float|int|string|null, auto_mapping?:  
          bool|float|int|string|null, ...}>, resolve_target_entities?: array<string, bool|float|int|string|null>}}, doctrine_migrations?: array{migrations_paths?: array<string, bool|float|int|string|null>, services?: array<string, bool|float|int  
         |string|null>, factories?: array<string, bool|float|int|string|null>, storage?: array{table_storage?: array{table_name?: bool|float|int|string|null, version_column_name?: bool|float|int|string|null, version_column_length?: bool|float|in  
         t|string|null, executed_at_column_name?: bool|float|int|string|null, execution_time_column_name?: bool|float|int|string|null}}, migrations?: list<bool|float|int|string|null>, connection?: bool|float|int|string|null, em?: bool|float|int|  
         string|null, all_or_nothing?: bool|float|int|string|null, ...}, doctrine_mongodb?: array{document_managers?: array<string, array{connection?: bool|float|int|string|null, database?: bool|float|int|string|null, logging?: bool, profiler?:   
         array{enabled?: bool, pretty?: bool}, default_document_repository_class?: bool|float|int|string|null, default_gridfs_repository_class?: bool|float|int|string|null, repository_factory?: bool|float|int|string|null,
         persistent_collection_factory?: bool|float|int|string|null, ...}>, connections?: array<string, array{server?: bool|float|int|string|null, options?: array{authMechanism?: 'GSSAPI'|'MONGODB-CR'|'MONGODB-X509'|'PLAIN'|'SCRAM-SHA-1'|'SCRAM-  
         SHA-256', connectTimeoutMS?: int, db?: bool|float|int|string|null, authSource?: bool|float|int|string|null, journal?: bool, password?: bool|float|int|string|null, readPreference?:
         'nearest'|'primary'|'primaryPreferred'|'secondary'|'secondaryPreferred', readPreferenceTags?: list<array<string, bool|float|int|string|null>>, ...}, driver_options?: array{context?: bool|float|int|string|null}, autoEncryption?: array{by  
         passAutoEncryption?: bool, keyVaultClient?: bool|float|int|string|null, keyVaultNamespace?: bool|float|int|string|null, masterKey?: list<mixed>, kmsProvider: array{type: bool|float|int|string|null, accessKeyId?: bool|float|int|string|nu  
         ll, secretAccessKey?: bool|float|int|string|null, sessionToken?: bool|float|int|string|null, tenantId?: bool|float|int|string|null, clientId?: bool|float|int|string|null, clientSecret?: bool|float|int|string|null, keyVaultEndpoint?:      
         bool|float|int|string|null, ...}, schemaMap?: list<mixed>, encryptedFieldsMap?: array<string, array{fields?: list<array{path: bool|float|int|string|null, bsonType: bool|float|int|string|null, keyId: mixed, queries?: array{queryType: boo  
         l|float|int|string|null, min?: mixed, max?: mixed, sparsity?: int, precision?: int, trimFactor?: int, contention?: int}}>}>, extraOptions?: array{mongocryptdURI?: bool|float|int|string|null, mongocryptdBypassSpawn?: bool, mongocryptdSpa  
         wnPath?: bool|float|int|string|null, mongocryptdSpawnArgs?: list<bool|float|int|string|null>, cryptSharedLibPath?: bool|float|int|string|null, cryptSharedLibRequired?: bool}, ...}}>, resolve_target_documents?: array<string, bool|float|i  
         nt|string|null>, types?: array<string, array{class: bool|float|int|string|null}|string>, proxy_namespace?: bool|float|int|string|null, proxy_dir?: bool|float|int|string|null, enable_lazy_ghost_objects?: bool, auto_generate_proxy_classes  
         ?: bool|float|int|string|null, ...}, framework?: array{secret?: bool|float|int|string|null, http_method_override?: bool, allowed_http_method_override?: list<string>|null, trust_x_sendfile_type_header?: bool|float|int|string|null, ide?:   
         bool|float|int|string|null, test?: bool, default_locale?: bool|float|int|string|null, set_locale_from_accept_language?: bool, ...}, lexik_jwt_authentication?: array{public_key?: bool|float|int|string|null, additional_public_keys?: list<  
         bool|float|int|string|null>, secret_key?: bool|float|int|string|null, pass_phrase?: bool|float|int|string|null, token_ttl?: bool|float|int|string|null, allow_no_expiration?: bool, clock_skew?: bool|float|int|string|null, encoder?: array  
         {service?: bool|float|int|string|null, signature_algorithm?: bool|float|int|string|null}, ...}, ...}, array{'when@prod': array{framework: array{router: array{strict_requirements: null}}}} given.
         🪪  argument.type
         💡  Offset 'when@prod' (array{imports?: list<array{resource: string, type?: string|null, ignore_errors?: bool}|string>, parameters?: array<string, array<int|string, array<int|string, mixed>|bool|float|int|string|UnitEnum|null>|bool|float 

         |int|string|UnitEnum|null>, services?: array{_defaults?: array{public?: bool, tags?: mixed, resource_tags?: mixed, autowire?: bool, autoconfigure?: bool, bind?: array<string, mixed>}, _instanceof?: array{shared?: bool, lazy?: bool|strin  
         g, public?: bool, properties?: array<string, mixed>, configurator?: array{string|Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator, string}|Closure|string|Symfony\Component\DependencyInjection\Loader\Config  
         urator\ExpressionConfigurator|Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator, calls?: list<array<0|1|2|string, array<int<0, max>|string, mixed>|bool|string>>, tags?: mixed, resource_tags?: mixed, ...}},   
         doctrine?: array{dbal?: array{default_connection?: bool|float|int|string|null, types?: array<string, array{class: bool|float|int|string|null}|string>, driver_schemes?: array<string, bool|float|int|string|null>, connections?: array<strin  
         g, array{url?: bool|float|int|string|null, dbname?: bool|float|int|string|null, host?: bool|float|int|string|null, port?: bool|float|int|string|null, user?: bool|float|int|string|null, password?: bool|float|int|string|null,
         dbname_suffix?: bool|float|int|string|null, application_name?: bool|float|int|string|null, ...}>}, orm?: array{default_entity_manager?: bool|float|int|string|null, enable_native_lazy_objects?: bool, controller_resolver?: array{enabled?:  
          bool, auto_mapping?: bool, evict_cache?: bool}|bool, entity_managers?: array<string, array{query_cache_driver?: array{type?: bool|float|int|string|null, id?: bool|float|int|string|null, pool?: bool|float|int|string|null}|string,
         metadata_cache_driver?: array{type?: bool|float|int|string|null, id?: bool|float|int|string|null, pool?: bool|float|int|string|null}|string, result_cache_driver?: array{type?: bool|float|int|string|null, id?: bool|float|int|string|null,  
         pool?: bool|float|int|string|null}|string, entity_listeners?: array{entities?: array<string, array{listeners?: array<string, array{events?: list<array{type?: bool|float|int|string|null, method?: bool|float|int|string|null}>}>}>}, connec  
         tion?: bool|float|int|string|null, class_metadata_factory_name?: bool|float|int|string|null, default_repository_class?: bool|float|int|string|null, auto_mapping?: bool|float|int|string|null, ...}>, resolve_target_entities?: array<string  
         , bool|float|int|string|null>}}, doctrine_migrations?: array{migrations_paths?: array<string, bool|float|int|string|null>, services?: array<string, bool|float|int|string|null>, factories?: array<string, bool|float|int|string|null>, stor  
         age?: array{table_storage?: array{table_name?: bool|float|int|string|null, version_column_name?: bool|float|int|string|null, version_column_length?: bool|float|int|string|null, executed_at_column_name?: bool|float|int|string|null,        
         execution_time_column_name?: bool|float|int|string|null}}, migrations?: list<bool|float|int|string|null>, connection?: bool|float|int|string|null, em?: bool|float|int|string|null, all_or_nothing?: bool|float|int|string|null, ...}, doctr  
         ine_mongodb?: array{document_managers?: array<string, array{connection?: bool|float|int|string|null, database?: bool|float|int|string|null, logging?: bool, profiler?: array{enabled?: bool, pretty?: bool}, default_document_repository_cla  
         ss?: bool|float|int|string|null, default_gridfs_repository_class?: bool|float|int|string|null, repository_factory?: bool|float|int|string|null, persistent_collection_factory?: bool|float|int|string|null, ...}>, connections?: array<strin  
         g, array{server?: bool|float|int|string|null, options?: array{authMechanism?: 'GSSAPI'|'MONGODB-CR'|'MONGODB-X509'|'PLAIN'|'SCRAM-SHA-1'|'SCRAM-SHA-256', connectTimeoutMS?: int, db?: bool|float|int|string|null, authSource?:
         bool|float|int|string|null, journal?: bool, password?: bool|float|int|string|null, readPreference?: 'nearest'|'primary'|'primaryPreferred'|'secondary'|'secondaryPreferred', readPreferenceTags?: list<array<string, bool|float|int|string|n  
         ull>>, ...}, driver_options?: array{context?: bool|float|int|string|null}, autoEncryption?: array{bypassAutoEncryption?: bool, keyVaultClient?: bool|float|int|string|null, keyVaultNamespace?: bool|float|int|string|null, masterKey?: list  
         <mixed>, kmsProvider: array{type: bool|float|int|string|null, accessKeyId?: bool|float|int|string|null, secretAccessKey?: bool|float|int|string|null, sessionToken?: bool|float|int|string|null, tenantId?: bool|float|int|string|null, clie  
         ntId?: bool|float|int|string|null, clientSecret?: bool|float|int|string|null, keyVaultEndpoint?: bool|float|int|string|null, ...}, schemaMap?: list<mixed>, encryptedFieldsMap?: array<string, array{fields?: list<array{path: bool|float|in  
         t|string|null, bsonType: bool|float|int|string|null, keyId: mixed, queries?: array{queryType: bool|float|int|string|null, min?: mixed, max?: mixed, sparsity?: int, precision?: int, trimFactor?: int, contention?: int}}>}>, extraOptions?:  
          array{mongocryptdURI?: bool|float|int|string|null, mongocryptdBypassSpawn?: bool, mongocryptdSpawnPath?: bool|float|int|string|null, mongocryptdSpawnArgs?: list<bool|float|int|string|null>, cryptSharedLibPath?: bool|float|int|string|nu  
         ll, cryptSharedLibRequired?: bool}, ...}}>, resolve_target_documents?: array<string, bool|float|int|string|null>, types?: array<string, array{class: bool|float|int|string|null}|string>, proxy_namespace?: bool|float|int|string|null, prox  
         y_dir?: bool|float|int|string|null, enable_lazy_ghost_objects?: bool, auto_generate_proxy_classes?: bool|float|int|string|null, ...}, framework?: array{secret?: bool|float|int|string|null, http_method_override?: bool,
         allowed_http_method_override?: list<string>|null, trust_x_sendfile_type_header?: bool|float|int|string|null, ide?: bool|float|int|string|null, test?: bool, default_locale?: bool|float|int|string|null, set_locale_from_accept_language?: b  
         ool, ...}, lexik_jwt_authentication?: array{public_key?: bool|float|int|string|null, additional_public_keys?: list<bool|float|int|string|null>, secret_key?: bool|float|int|string|null, pass_phrase?: bool|float|int|string|null, token_ttl  
         ?: bool|float|int|string|null, allow_no_expiration?: bool, clock_skew?: bool|float|int|string|null, encoder?: array{service?: bool|float|int|string|null, signature_algorithm?: bool|float|int|string|null}, ...}, ...}) does not accept      
         type array{framework: array{router: array{strict_requirements: null}}}: Offset 'framework' (array{secret?: bool|float|int|string|null, http_method_override?: bool, allowed_http_method_override?: list<string>|null, trust_x_sendfile_type_  
         header?: bool|float|int|string|null, ide?: bool|float|int|string|null, test?: bool, default_locale?: bool|float|int|string|null, set_locale_from_accept_language?: bool, ...}) does not accept type array{router: array{strict_requirements:  
         null}}: Offset 'router' (array{enabled?: bool, resource: bool|float|int|string|null, type?: bool|float|int|string|null, cache_dir?: bool|float|int|string|null, default_uri?: bool|float|int|string|null, http_port?:
         bool|float|int|string|null, https_port?: bool|float|int|string|null, strict_requirements?: bool|float|int|string|null, ...}|bool) does not accept type array{strict_requirements: null}: Type #1 from the union: Array does not have offset   
         'resource'.
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 


                                                                                                                        
 [ERROR] Found 1 error                                                                                                  
                                                                                                                        

Script phpstan --memory-limit=-1 --ansi handling the phpstan event returned with error code 1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions