Skip to content

Commit

Permalink
More cleanup for 4.x
Browse files Browse the repository at this point in the history
* Rename console-and-shells to console-commands. This change aims to
  better match our directory structure with the undeprecated features.
* Remove most mentions of shells. With shells on the way out, we
  shouldn't mention them as often as the term could be confusing.
* Fix broken links and formatting.
  • Loading branch information
markstory committed Apr 8, 2019
1 parent 5670bab commit 914c7cd
Show file tree
Hide file tree
Showing 33 changed files with 248 additions and 415 deletions.
2 changes: 1 addition & 1 deletion en/bake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Installation
Before trying to use or extend bake, make sure it is installed in your
application. Bake is provided as a plugin that you can install with Composer::

composer require --dev cakephp/bake:~1.0
composer require --dev cakephp/bake:~2.0

The above will install bake as a development dependency. This means that it will
not be installed when you do production deployments.
Expand Down
99 changes: 43 additions & 56 deletions en/bake/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ view class which uses the `Twig <https://twig.symfony.com/>`_ template engine.
Bake Events
===========

As a view class, ``BakeView`` emits the same events as any other view class,
plus one extra initialize event. However, whereas standard view classes use the
event prefix "View.", ``BakeView`` uses the event prefix "Bake.".
As a view class, ``BakeView`` emits the similar events to the standard view
classes, but prefixed with ``Bake.`` instead of ``View.``.

The initialize event can be used to make changes which apply to all baked
The ``Bake.initialize`` event can be used to make changes which apply to all baked
output, for example to add another helper to the bake view class this event can
be used::

Expand Down Expand Up @@ -112,57 +111,37 @@ to modify bake template files, is to bake a class and compare the template used
with the pre-processed template file which is left in the application's
**tmp/bake** folder.

So, for example, when baking a shell like so:
So, for example, when baking a command like so:

.. code-block:: bash
bin/cake bake shell Foo
bin/cake bake command Foo
The template used (**vendor/cakephp/bake/templates/Bake/Shell/shell.twig**)
The template used (**vendor/cakephp/bake/templates/Bake/Command/command.twig**)
looks like this::

<?php
namespace {{ namespace }}\Shell;

use Cake\Console\Shell;
use Cake\Console\Arguments;
use Cake\Console\Command;
use Cake\Console\ConsoleIo;

/**
* {{ name }} shell command.
* {{ name }} command.
*/
class {{ name }}Shell extends Shell
class {{ name }}Command extends Command
{
/**
* main() method.
* Implement this method with your command's logic.
*
* @return bool|int Success or error code.
* @param \Cake\Console\Arguments $args The command arguments.
* @param \Cake\Console\ConsoleIo $io The console io
* @return null|int The exit code or null for success
*/
public function main()
public function execute(Arguments $args, ConsoleIo $io)
{
}

}

And the resultant baked class (**src/Shell/FooShell.php**) looks like this::

<?php
namespace App\Shell;

use Cake\Console\Shell;

/**
* Foo shell command.
*/
class FooShell extends Shell
{
/**
* main() method.
*
* @return bool|int Success or error code.
*/
public function main()
{
}

}

.. _creating-a-bake-theme:
Expand Down Expand Up @@ -204,36 +183,36 @@ Creating New Bake Command Options

It's possible to add new bake command options, or override the ones provided by
CakePHP by creating tasks in your application or plugins. By extending
``Bake\Shell\Task\BakeTask``, bake will find your new task and include it as
part of bake.
``Bake\Command\BakeCommand`` or ``SimpleBakeCommand``, bake will find your new
task and include it as part of bake.

As an example, we'll make a task that creates an arbitrary foo class. First,
create the task file **src/Shell/Task/FooTask.php**. We'll extend the
``SimpleBakeTask`` for now as our shell task will be simple. ``SimpleBakeTask``
is abstract and requires us to define 3 methods that tell bake what the task is
create the task file **src/Command/FooCommand.php**. We'll extend the
``SimpleBakeCommand`` for now as we don't need any logic to generate our code. ``SimpleBakeTask``
requires us to define 3 methods that tell bake what the task is
called, where the files it generates should go, and what template to use. Our
FooTask.php file should look like::
``FooCommand.php`` file should look like::

<?php
namespace App\Shell\Task;
namespace App\Command;

use Bake\Shell\Task\SimpleBakeTask;
use Bake\Command\SimpleBakeCommand;

class FooTask extends SimpleBakeTask
class FooCommand extends SimpleBakeCommand
{
public $pathFragment = 'Foo/';

public function name()
public function name(): string
{
return 'foo';
}

public function fileName($name)
public function fileName(string $name): string
{
return $name . 'Foo.php';
}

public function template()
public function template(): string
{
return 'foo';
}
Expand Down Expand Up @@ -262,19 +241,27 @@ for your application to use.

If you want the ``bake`` call to also create a test file for your
``ExampleFoo`` class, you need to overwrite the ``bakeTest()`` method in the
``FooTask`` class to register the class suffix and namespace for your custom
``FooCommand`` class to register the class suffix and namespace for your custom
command name::

public function bakeTest($className)

public function bakeTest(string $className, Arguments $args, ConsoleIo $io): void
{
if (!isset($this->Test->classSuffixes[$this->name()])) {
$this->Test->classSuffixes[$this->name()] = 'Foo';
if ($args->getOption('no-test')) {
return;
}
$test = new \Bake\Command\TestCommand();
$test->plugin = $this->plugin;

$name = ucfirst($this->name());
if (!isset($this->Test->classTypes[$name])) {
$this->Test->classTypes[$name] = 'Foo';
$name = $this->name();
if (!isset($test->classSuffixes[$name])) {
$test->classSuffixes[$name] = 'Foo';
}
$title = ucfirst($name);
if (!isset($test->classTypes[$title])) {
$test->classTypes[$title] = 'Foo';
}
$test->bake($name, $className, $args, $io);

return parent::bakeTest($className);
}
Expand Down
136 changes: 43 additions & 93 deletions en/bake/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,107 +17,57 @@ tasks.

For windows system try with ``bin\cake bake``.

You should see something like::

$ bin/cake bake

Welcome to CakePHP v3.4.6 Console
---------------------------------------------------------------
App : src
Path: /var/www/cakephp.dev/src/
PHP : 5.6.20
---------------------------------------------------------------
The following commands can be used to generate skeleton code for your application.

Available bake commands:

- all
- behavior
- cell
- component
- controller
- fixture
- form
- helper
- mailer
- migration
- migration_diff
- migration_snapshot
- model
- plugin
- seed
- shell
- shell_helper
- task
- template
- test

By using `cake bake [name]` you can invoke a specific bake task.

You can get more information on what each task does, and what options are
available using the ``--help`` option::

$ bin/cake bake --help

Welcome to CakePHP v3.4.6 Console
---------------------------------------------------------------
App : src
Path: /var/www/cakephp.dev/src/
PHP : 5.6.20
---------------------------------------------------------------
The Bake script generates controllers, models and template files for
your application. If run with no command line arguments, Bake guides the
user through the class creation process. You can customize the
generation process by telling Bake where different parts of your
application are using command line arguments.
You should see something like:

.. code-block:: bash
$ bin/cake bake -h
Bake generates code for your application. Different types of classes can
be generated with the subcommands listed below. For example run
bake controller --help to learn more about generating a
controller.
Usage:
cake bake.bake [subcommand] [options]
cake bake [subcommand] [-h] [-q] [-v]
Subcommands:
all Bake a complete MVC skeleton.
behavior Bake a behavior class file.
cell Bake a cell class file.
component Bake a component class file.
controller Bake a controller skeleton.
fixture Generate fixtures for use with the test suite. You
can use `bake fixture all` to bake all fixtures.
form Bake a form class file.
helper Bake a helper class file.
mailer Bake a mailer class file.
migration Bake migration class.
migration_diff Bake migration class.
migration_snapshot Bake migration snapshot class.
model Bake table and entity classes.
plugin Create the directory structure, AppController class
and testing setup for a new plugin. Can create
plugins in any of your bootstrapped plugin paths.
seed Bake seed class.
shell Bake a shell class file.
shell_helper Bake a shell_helper class file.
task Bake a task class file.
template Bake views for a controller, using built-in or
custom templates.
test Bake test case skeletons for classes.

To see help on a subcommand use `cake bake.bake [subcommand] --help`
all Generate all files.
behavior Generate behavior files.
cell Generate cell files.
command Generate command files.
component Generate component files.
controller Generate controller files.
controller all Generate controller files.
fixture Generate fixture files.
fixture all Generate fixture files.
form Generate form files.
helper Generate helper files.
mailer Generate mailer files.
middleware Generate middleware files.
model Generate model files.
model all Generate model files.
plugin Generate plugin files.
shell Generate shell files.
shell_helper Generate shell helper files.
task Generate task files.
template Generate template files.
template all Generate template files.
test Generate test files.
To see help on a subcommand use `cake bake [subcommand] --help`
Options:
--connection, -c Database connection to use in conjunction with `bake
all`. (default: default)
--everything Bake a complete MVC skeleton, using all the available
tables. Usage: "bake all --everything"
--force, -f Force overwriting existing files without prompting.
--help, -h Display this help.
--plugin, -p Plugin to bake into.
--prefix Prefix to bake controllers and templates into.
--quiet, -q Enable quiet output.
--tablePrefix Table prefix to be used in models.
--theme, -t The theme to use when baking code. (choices:
Bake|Migrations)
--verbose, -v Enable verbose output.
--help, -h Display this help.
--quiet, -q Enable quiet output.
--verbose, -v Enable verbose output.
Older Shell based tasks will not be listed here, but can still be run.
You can get more information on each command using the ``-h`` option. e.g:
``bin/cake controller -h``.

Bake Themes
===========
Expand Down
5 changes: 0 additions & 5 deletions en/console-and-shells/helpers.rst

This file was deleted.

15 changes: 0 additions & 15 deletions en/console-and-shells/upgrade-shell.rst

This file was deleted.

Loading

0 comments on commit 914c7cd

Please sign in to comment.