|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Bug7954; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertType; |
| 6 | + |
| 7 | +/** |
| 8 | + * @phpstan-type ExtensionMap = array<string, array{ |
| 9 | + * global: bool, |
| 10 | + * excludes: array<string, string>, |
| 11 | + * admins: array<string, string>, |
| 12 | + * implements: array<class-string, string>, |
| 13 | + * extends: array<class-string, string>, |
| 14 | + * instanceof: array<class-string, string>, |
| 15 | + * uses: array<class-string, string>, |
| 16 | + * priority: int, |
| 17 | + * }> |
| 18 | + * @phpstan-type SonataAdminConfigurationOptions = array{ |
| 19 | + * confirm_exit: bool, |
| 20 | + * default_admin_route: string, |
| 21 | + * default_group: string, |
| 22 | + * default_icon: string, |
| 23 | + * default_translation_domain: string, |
| 24 | + * default_label_catalogue: string, |
| 25 | + * dropdown_number_groups_per_colums: int, |
| 26 | + * form_type: 'standard'|'horizontal', |
| 27 | + * html5_validate: bool, |
| 28 | + * js_debug: bool, |
| 29 | + * list_action_button_content: 'text'|'icon'|'all', |
| 30 | + * lock_protection: bool, |
| 31 | + * logo_content: 'text'|'icon'|'all', |
| 32 | + * mosaic_background: string, |
| 33 | + * pager_links: int|null, |
| 34 | + * skin: 'skin-black'|'skin-black-light'|'skin-blue'|'skin-blue-light'|'skin-green'|'skin-green-light'|'skin-purple'|'skin-purple-light'|'skin-red'|'skin-red-light'|'skin-yellow'|'skin-yellow-light', |
| 35 | + * sort_admins: bool, |
| 36 | + * use_bootlint: bool, |
| 37 | + * use_icheck: bool, |
| 38 | + * use_select2: bool, |
| 39 | + * use_stickyforms: bool, |
| 40 | + * } |
| 41 | + * @phpstan-type SonataAdminConfiguration = array{ |
| 42 | + * assets: array{ |
| 43 | + * extra_javascripts: list<string>, |
| 44 | + * extra_stylesheets: list<string>, |
| 45 | + * javascripts: list<string>, |
| 46 | + * remove_javascripts: list<string>, |
| 47 | + * remove_stylesheets: list<string>, |
| 48 | + * stylesheets: list<string>, |
| 49 | + * }, |
| 50 | + * breadcrumbs: array{ |
| 51 | + * child_admin_route: string, |
| 52 | + * }, |
| 53 | + * dashboard: array{ |
| 54 | + * blocks: array{ |
| 55 | + * class: string, |
| 56 | + * position: string, |
| 57 | + * roles: list<string>, |
| 58 | + * settings: array<string, mixed>, |
| 59 | + * type: string, |
| 60 | + * }, |
| 61 | + * groups: array<string, array{ |
| 62 | + * label?: string, |
| 63 | + * translation_domain?: string, |
| 64 | + * icon?: string, |
| 65 | + * items: array<Item>, |
| 66 | + * keep_open: bool, |
| 67 | + * on_top: bool, |
| 68 | + * provider?: string, |
| 69 | + * roles: list<string> |
| 70 | + * }>, |
| 71 | + * }, |
| 72 | + * default_admin_services: array{ |
| 73 | + * configuration_pool: string|null, |
| 74 | + * datagrid_builder: string|null, |
| 75 | + * data_source: string|null, |
| 76 | + * field_description_factory: string|null, |
| 77 | + * form_contractor: string|null, |
| 78 | + * label_translator_strategy: string|null, |
| 79 | + * list_builder: string|null, |
| 80 | + * menu_factory: string|null, |
| 81 | + * model_manager: string|null, |
| 82 | + * pager_type: string|null, |
| 83 | + * route_builder: string|null, |
| 84 | + * route_generator: string|null, |
| 85 | + * security_handler: string|null, |
| 86 | + * show_builder: string|null, |
| 87 | + * translator: string|null, |
| 88 | + * }, |
| 89 | + * default_controller: string, |
| 90 | + * extensions: array<string, ExtensionMap>, |
| 91 | + * filter_persister: string, |
| 92 | + * global_search: array{ |
| 93 | + * admin_route: string, |
| 94 | + * empty_boxes: 'show'|'fade'|'hide', |
| 95 | + * }, |
| 96 | + * options: SonataAdminConfigurationOptions, |
| 97 | + * persist_filters: bool, |
| 98 | + * security: array{ |
| 99 | + * acl_user_manager: string|null, |
| 100 | + * admin_permissions: list<string>, |
| 101 | + * information: array<string, list<string>>, |
| 102 | + * object_permissions: list<string>, |
| 103 | + * handler: string, |
| 104 | + * role_admin: string, |
| 105 | + * role_super_admin: string, |
| 106 | + * }, |
| 107 | + * search: bool, |
| 108 | + * show_mosaic_button: bool, |
| 109 | + * templates: array{ |
| 110 | + * acl: string, |
| 111 | + * action: string, |
| 112 | + * action_create: string, |
| 113 | + * add_block: string, |
| 114 | + * ajax: string, |
| 115 | + * base_list_field: string, |
| 116 | + * batch: string, |
| 117 | + * batch_confirmation: string, |
| 118 | + * button_acl: string, |
| 119 | + * button_create: string, |
| 120 | + * button_edit: string, |
| 121 | + * button_history: string, |
| 122 | + * button_list: string, |
| 123 | + * button_show: string, |
| 124 | + * dashboard: string, |
| 125 | + * delete: string, |
| 126 | + * edit: string, |
| 127 | + * filter: string, |
| 128 | + * filter_theme: list<string>, |
| 129 | + * form_theme: list<string>, |
| 130 | + * history: string, |
| 131 | + * history_revision_timestamp: string, |
| 132 | + * inner_list_row: string, |
| 133 | + * knp_menu_template: string, |
| 134 | + * layout: string, |
| 135 | + * list: string, |
| 136 | + * list_block: string, |
| 137 | + * outer_list_rows_list: string, |
| 138 | + * outer_list_rows_mosaic: string, |
| 139 | + * outer_list_rows_tree: string, |
| 140 | + * pager_links: string, |
| 141 | + * pager_results: string, |
| 142 | + * preview: string, |
| 143 | + * search: string, |
| 144 | + * search_result_block: string, |
| 145 | + * select: string, |
| 146 | + * short_object_description: string, |
| 147 | + * show: string, |
| 148 | + * show_compare: string, |
| 149 | + * tab_menu_template: string, |
| 150 | + * user_block: string, |
| 151 | + * }, |
| 152 | + * title: string, |
| 153 | + * title_logo: string, |
| 154 | + * } |
| 155 | + **/ |
| 156 | +class HelloWorld |
| 157 | +{ |
| 158 | + /** @param SonataAdminConfiguration $config */ |
| 159 | + public function sayHello(array $config): void |
| 160 | + { |
| 161 | + assertType('string', $config['security']['role_admin']); |
| 162 | + |
| 163 | + if (false === $config['options']['lock_protection']) { |
| 164 | + // things |
| 165 | + } |
| 166 | + |
| 167 | + assertType('string', $config['security']['role_admin']); |
| 168 | + |
| 169 | + switch ($config['security']['handler']) { |
| 170 | + case 'sonata.admin.security.handler.role': |
| 171 | + if (0 === \count($config['security']['information'])) { |
| 172 | + $config['security']['information'] = [ |
| 173 | + 'EDIT' => ['EDIT'], |
| 174 | + 'LIST' => ['LIST'], |
| 175 | + 'CREATE' => ['CREATE'], |
| 176 | + 'VIEW' => ['VIEW'], |
| 177 | + 'DELETE' => ['DELETE'], |
| 178 | + 'EXPORT' => ['EXPORT'], |
| 179 | + 'ALL' => ['ALL'], |
| 180 | + ]; |
| 181 | + } |
| 182 | + |
| 183 | + break; |
| 184 | + case 'sonata.admin.security.handler.acl': |
| 185 | + if (0 === \count($config['security']['information'])) { |
| 186 | + $config['security']['information'] = [ |
| 187 | + 'GUEST' => ['VIEW', 'LIST'], |
| 188 | + 'STAFF' => ['EDIT', 'LIST', 'CREATE'], |
| 189 | + 'EDITOR' => ['OPERATOR', 'EXPORT'], |
| 190 | + 'ADMIN' => ['MASTER'], |
| 191 | + ]; |
| 192 | + } |
| 193 | + |
| 194 | + break; |
| 195 | + } |
| 196 | + |
| 197 | + assertType('string', $config['security']['role_admin']); |
| 198 | + } |
| 199 | +} |
0 commit comments