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

Load bootstrap_cli.php of a plugin #11184

Closed
1 of 3 tasks
igorfelluga opened this issue Sep 14, 2017 · 8 comments
Closed
1 of 3 tasks

Load bootstrap_cli.php of a plugin #11184

igorfelluga opened this issue Sep 14, 2017 · 8 comments

Comments

@igorfelluga
Copy link

igorfelluga commented Sep 14, 2017

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 3.5.2

What you did

In documentation (https://book.cakephp.org/3.0/en/console-and-shells/plugin-shell.html#loading-plugins) I found that to load bootstrap_cli of a plugin I must use bin/cake plugin load --cli MyPlugin, that add
Plugin::load('MyPlugin');
but it didn't load it.

@markstory
Copy link
Member

That bake command modifies the applicationbootstrap_cli.php instead of the general one. It does not change how plugin bootstrapping works.

If plugins have cli only bootstrap code, it is up to each plugin to conditionally load it as necessary. Perhaps in the future plugins will have a more formalized pattern for this.

@igorfelluga
Copy link
Author

igorfelluga commented Sep 18, 2017

Is there a way that when I use command
bin/cake bake template Features --prefix Admin -t MyTheme
it load the plugin bootstrap_cli where I have setted this event ?

EventManager::instance()->on(
    'Bake.beforeRender.Controller.controller',
    function (Event $event) {
        $view = $event->getSubject();
            // add the login and logout actions to the Users controller
            $view->viewVars['actions'] = [
                'index',
                'view',
                'add',
                'edit',
                'delete',
                'online'
            ];
    }
);

@dereuromark
Copy link
Member

@igorfelluga I updated your post to properly highlight the code. Please see the format and add it yourself for future posts like this.

@markstory
Copy link
Member

@igorfelluga Of course there is.

// in YourPlugin/config/bootstrap.php

// other code

if (PHP_SAPI === 'cli') {
    require __DIR__ . '/bootstrap_cli.php';
}

@igorfelluga
Copy link
Author

Thanks

@dereuromark
Copy link
Member

Can be part of #11564 discussion.

@Tomicapo
Copy link

Tomicapo commented Jul 6, 2018

@markstory I tried implementing your suggestion to make "bake" use my plugin's bootstrap_cli but it didn't work.

My plugin is being loaded here:

app/config/bootstrap.php

// rest of the file
Plugin::load('CoderThemes', ['bootstrap' => true, 'routes' => true]);

app/plugins/CoderThemes/config/bootstrap.php

// this is not being reached
if (PHP_SAPI === 'cli') {
	require __DIR__ . '/bootstrap_cli.php';
}

The code above (plugin/boostrap) never get executed when running bin/cake bake controller Whatever
I even tried to add -t CoderThemes but still, nothing happened.

CakePHP version: 3.6.6
Bake version: 1.8.1
OS: Windows 10
Server: Xampp

Am I doing something wrong?

@markstory
Copy link
Member

Does your plugin's bootstrap file run at all?

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

No branches or pull requests

5 participants