Skip to content
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

Plugin routes config files are included twice #593

Closed
1 of 3 tasks
Schlaefer opened this issue Apr 20, 2018 · 6 comments
Closed
1 of 3 tasks

Plugin routes config files are included twice #593

Schlaefer opened this issue Apr 20, 2018 · 6 comments
Assignees
Milestone

Comments

@Schlaefer
Copy link
Contributor

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Application Skeleton Version: 3.6.0

  • Platform and Target: CakePHP 3.6.0

What you did

register a Plugin with routes in bootstrap.php

Plugin::loadAll([
    'Foo' => ['routes' => true],
]);

What happened

The routes file plugins/Foo/config/routes.php is included twice.

What you expected to happen

The routes file should only be included once.

I assume the call to Plugins::routes() in config/routes.php isn't necessary in Cake 3.6 anymore?

@markstory markstory added this to the 3.6.x milestone Apr 20, 2018
@markstory
Copy link
Member

This was a problem in an one of the rc releases, but that issue was fixed. What are the stack traces for each include? You can use debug(stackTrace()) to output a stack trace.

@Schlaefer
Copy link
Contributor Author

Schlaefer commented Apr 21, 2018

What I did:

  1. composer create-project --prefer-dist cakephp/app .
Installing cakephp/app (3.6.0)
  - Installing cakephp/app (3.6.0): Loading from cache
Created project in .
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 47 installs, 0 updates, 0 removals
  - Installing cakephp/plugin-installer (1.1.0): Loading from cache
  - Installing aura/intl (3.0.0): Loading from cache
  - Installing psr/http-message (1.0.1): Loading from cache
  - Installing zendframework/zend-diactoros (1.7.1): Loading from cache
  - Installing psr/log (1.0.2): Loading from cache
  - Installing cakephp/chronos (1.1.4): Loading from cache
  - Installing cakephp/cakephp (3.6.1): Loading from cache
  - Installing symfony/yaml (v3.4.8): Loading from cache
  - Installing symfony/debug (v4.0.8): Loading from cache
  - Installing symfony/polyfill-mbstring (v1.7.0): Loading from cache
  - Installing symfony/console (v3.4.8): Loading from cache
  - Installing symfony/filesystem (v4.0.8): Loading from cache
  - Installing symfony/config (v3.4.8): Loading from cache
  - Installing robmorgan/phinx (v0.8.1): Loading from cache
  - Installing cakephp/migrations (1.8.1): Loading from cache
  - Installing m1/env (2.1.0): Loading from cache
  - Installing josegonzalez/dotenv (3.2.0): Loading from cache
  - Installing mobiledetect/mobiledetectlib (2.8.31): Loading from cache
  - Installing twig/twig (v1.35.3): Loading from cache
  - Installing umpirsky/twig-php-function (v0.1): Loading from cache
  - Installing jasny/twig-extensions (v1.2.0): Loading from cache
  - Installing asm89/twig-cache-extension (1.3.2): Loading from cache
  - Installing aptoma/twig-markdown (2.0.0): Loading from cache
  - Installing ajgl/breakpoint-twig-extension (0.3.1): Loading from cache
  - Installing wyrihaximus/twig-view (4.3.4): Loading from cache
  - Installing cakephp/bake (1.7.0): Loading from cache
  - Installing squizlabs/php_codesniffer (3.2.3): Loading from cache
  - Installing cakephp/cakephp-codesniffer (3.0.3): Loading from cache
  - Installing jdorn/sql-formatter (v1.2.17): Loading from cache
  - Installing symfony/process (v4.0.8): Loading from cache
  - Installing symfony/finder (v4.0.8): Loading from cache
  - Installing seld/phar-utils (1.0.1): Loading from cache
  - Installing seld/jsonlint (1.7.1): Loading from cache
  - Installing seld/cli-prompt (1.0.3): Loading from cache
  - Installing justinrainbow/json-schema (5.2.7): Loading from cache
  - Installing composer/spdx-licenses (1.3.0): Loading from cache
  - Installing composer/semver (1.4.2): Loading from cache
  - Installing composer/ca-bundle (1.1.1): Loading from cache
  - Installing composer/composer (1.6.4): Loading from cache
  - Installing cakephp/debug_kit (3.15.1): Loading from cache
  - Installing jakub-onderka/php-console-color (0.1): Loading from cache
  - Installing jakub-onderka/php-console-highlighter (v0.3.2): Loading from cache
  - Installing dnoegel/php-xdg-base-dir (0.1): Loading from cache
  - Installing nikic/php-parser (v4.0.1): Loading from cache
  - Installing symfony/polyfill-php72 (v1.7.0): Loading from cache
  - Installing symfony/var-dumper (v4.0.8): Loading from cache
  - Installing psy/psysh (v0.9.3): Loading from cache
  1. create plugins/Foo/config/routes.php with debug(stackTrace()) in it
  2. put "Foo\\": "plugins/Foo" in composer and dumpautoload
  3. activated plugin in config/bootstrap.php Plugin::load('Foo', ['routes' => true]);

Stacktrace:

  | include - ROOT/plugins/Foo/config/routes.php, line 4
-- | --
  | Cake\Core\Plugin::_includeFile() - CORE/src/Core/Plugin.php, line 406
  | Cake\Core\Plugin::routes() - CORE/src/Core/Plugin.php, line 352
  | Cake\Core\Plugin::routes() - CORE/src/Core/Plugin.php, line 340
  | require - ROOT/config/routes.php, line 85
  | Cake\Http\BaseApplication::routes() - CORE/src/Http/BaseApplication.php, line 172
  | Cake\Routing\Middleware\RoutingMiddleware::prepareRouteCollection() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 110
  | Cake\Routing\Middleware\RoutingMiddleware::Cake\Routing\Middleware\{closure}() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 95
  | call_user_func - [internal], line ??
  | Cake\Cache\Cache::remember() - CORE/src/Cache/Cache.php, line 632
  | Cake\Routing\Middleware\RoutingMiddleware::buildRouteCollection() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 96
  | Cake\Routing\Middleware\RoutingMiddleware::loadRoutes() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 82
  | Cake\Routing\Middleware\RoutingMiddleware::__invoke() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 132
  | Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
  | Cake\Routing\Middleware\AssetMiddleware::__invoke() - CORE/src/Routing/Middleware/AssetMiddleware.php, line 88
  | Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
  | Cake\Error\Middleware\ErrorHandlerMiddleware::__invoke() - CORE/src/Error/Middleware/ErrorHandlerMiddleware.php, line 98
  | Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
  | DebugKit\Middleware\DebugKitMiddleware::__invoke() - ROOT/vendor/cakephp/debug_kit/src/Middleware/DebugKitMiddleware.php, line 53
  | Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
  | Cake\Http\Runner::run() - CORE/src/Http/Runner.php, line 51
  | Cake\Http\Server::run() - CORE/src/Http/Server.php, line 98
  | [main] - ROOT/webroot/index.php, line 40<div class="cake-debug-output">
  | <span><strong>/plugins/Foo/config/routes.php</strong> (line <strong>4</strong>)</span>
  | <pre class="cake-debug">
  | null
  | </pre>
  | </div>require - ROOT/plugins/Foo/config/routes.php, line 4
  | Cake\Core\BasePlugin::routes() - CORE/src/Core/BasePlugin.php, line 229
  | Cake\Http\BaseApplication::pluginRoutes() - CORE/src/Http/BaseApplication.php, line 182
  | Cake\Routing\Middleware\RoutingMiddleware::prepareRouteCollection() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 112
  | Cake\Routing\Middleware\RoutingMiddleware::Cake\Routing\Middleware\{closure}() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 95
  | call_user_func - [internal], line ??
  | Cake\Cache\Cache::remember() - CORE/src/Cache/Cache.php, line 632
  | Cake\Routing\Middleware\RoutingMiddleware::buildRouteCollection() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 96
  | Cake\Routing\Middleware\RoutingMiddleware::loadRoutes() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 82
  | Cake\Routing\Middleware\RoutingMiddleware::__invoke() - CORE/src/Routing/Middleware/RoutingMiddleware.php, line 132
  | Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
  | Cake\Routing\Middleware\AssetMiddleware::__invoke() - CORE/src/Routing/Middleware/AssetMiddleware.php, line 88
  | Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
  | Cake\Error\Middleware\ErrorHandlerMiddleware::__invoke() - CORE/src/Error/Middleware/ErrorHandlerMiddleware.php, line 98
  | Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
  | DebugKit\Middleware\DebugKitMiddleware::__invoke() - ROOT/vendor/cakephp/debug_kit/src/Middleware/DebugKitMiddleware.php, line 53
  | Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
  | Cake\Http\Runner::run() - CORE/src/Http/Runner.php, line 51
  | Cake\Http\Server::run() - CORE/src/Http/Server.php, line 98
  | [main] - ROOT/webroot/index.php, line 40<div class="cake-debug-output">
  | <span><strong>/plugins/Foo/config/routes.php</strong> (line <strong>4</strong>)</span>
  | <pre class="cake-debug">
  | null
  | </pre>

@markstory
Copy link
Member

Oh I hadn't considered usage of Plugin::routes() being called in the application routes.php file. We should be able to remove that methid call now.

@markstory markstory self-assigned this Apr 21, 2018
@josbeir
Copy link

josbeir commented Apr 30, 2018

I found this out the hard way, (exceptions about named routes already set). Removing Plugin::routes fixed it. Guess this should be mentioned somewhere in the docs and/or the app skeleton should be updated accordingly when releasing this breaking change as it is mostly the starting point for most new projects...

Also something to take note of is that the current implementation of RouterShell is unaware of any routes loaded by the RoutingMiddleware (which is of course logical but i thought it should mention this) thus making this shell script obsolete in favor of DebugKit's routes panel.

@markstory
Copy link
Member

the current implementation of RouterShell is unaware of any routes loaded by the RoutingMiddleware (which is of course logical but i thought it should mention this)

I can look into fixing this. I'm pretty sure we can figure out a clever solution to this.

@markstory
Copy link
Member

The issue with bin/cake routes is captured in cakephp/cakephp#12030

markstory added a commit that referenced this issue May 25, 2018
When using the new plugin system this method is no longer necessary as
the plugin classes include routes during application startup.

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

No branches or pull requests

3 participants