Skip to content

Commit 259bce8

Browse files
committed
Update docs
1 parent 510e053 commit 259bce8

26 files changed

Lines changed: 1792 additions & 852 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Bake plugin for CakePHP
22

3-
![Build Status](https://github.com/cakephp/bake/actions/workflows/ci.yml/badge.svg?branch=master)
3+
![Build Status](https://github.com/cakephp/bake/actions/workflows/ci.yml/badge.svg?branch=4.x)
44
[![Latest Stable Version](https://img.shields.io/github/v/release/cakephp/bake?sort=semver&style=flat-square)](https://packagist.org/packages/cakephp/bake)
55
[![Coverage Status](https://img.shields.io/codecov/c/github/cakephp/bake.svg?style=flat-square)](https://codecov.io/github/cakephp/bake)
66
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.txt)
@@ -20,7 +20,7 @@ composer require --dev cakephp/bake
2020

2121
## Documentation
2222

23-
You can find the documentation for bake [on its own cookbook](https://book.cakephp.org/bake/3).
23+
You can find the documentation for bake [on its own cookbook](https://book.cakephp.org/bake/4).
2424

2525
## Testing
2626

‎docs/.vitepress/config.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ const tocPt = require('./toc_pt.json')
1010
const tocRu = require('./toc_ru.json')
1111

1212
const versions = {
13-
text: '3.x',
13+
text: '4.x',
1414
items: [
15-
{ text: '3.x (current)', link: 'https://book.cakephp.org/bake/3/', target: '_self' },
15+
{ text: '4.x (current)', link: 'https://book.cakephp.org/bake/4/', target: '_self' },
16+
{ text: '3.x', link: 'https://book.cakephp.org/bake/3/', target: '_self' },
1617
{ text: '2.x', link: 'https://book.cakephp.org/bake/2.x/', target: '_self' },
1718
{ text: '1.x', link: 'https://book.cakephp.org/bake/1.x/', target: '_self' },
1819
],
@@ -23,12 +24,12 @@ export default {
2324
srcDir: '.',
2425
title: 'Bake',
2526
description: 'CakePHP Bake Documentation',
26-
base: '/bake/3/',
27+
base: '/bake/4/',
2728
rewrites: {
2829
'en/:slug*': ':slug*',
2930
},
3031
sitemap: {
31-
hostname: 'https://book.cakephp.org/bake/3/',
32+
hostname: 'https://book.cakephp.org/bake/4/',
3233
},
3334
themeConfig: {
3435
siteTitle: false,
@@ -37,7 +38,7 @@ export default {
3738
{ icon: 'github', link: 'https://github.com/cakephp/bake' },
3839
],
3940
editLink: {
40-
pattern: 'https://github.com/cakephp/bake/edit/3.x/docs/:path',
41+
pattern: 'https://github.com/cakephp/bake/edit/4.x/docs/:path',
4142
text: 'Edit this page on GitHub',
4243
},
4344
sidebar: tocEn,

‎docs/.vitepress/toc_es.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"items": [
77
{ "text": "Consola Bake", "link": "/es/" },
88
{ "text": "Crear código con Bake", "link": "/es/usage" },
9-
{ "text": "Extending Bake", "link": "/es/development" }
9+
{ "text": "Extender Bake", "link": "/es/development" }
1010
]
1111
}
1212
]

‎docs/en/development.md‎

Lines changed: 108 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ For instance, if you want to add specific actions to your `UsersController` when
6868
<?php
6969
use Cake\Event\EventInterface;
7070
use Cake\Event\EventManager;
71-
use Cake\Utility\Hash;
7271

7372
// in src/Application::bootstrapCli()
7473

@@ -107,48 +106,73 @@ bin/cake bake command Foo
107106
The template used at `vendor/cakephp/bake/templates/bake/Command/command.twig` looks like this:
108107

109108
```php
110-
<?php
111-
declare(strict_types=1);
112-
113-
namespace {{ namespace }}\Command;
114-
115-
use Cake\Command\Command;
116-
use Cake\Console\Arguments;
117-
use Cake\Console\ConsoleIo;
118-
use Cake\Console\ConsoleOptionParser;
109+
{{ element('Bake.file_header', {
110+
namespace: "#{namespace}\\Command",
111+
classImports: [
112+
'Cake\\Command\\Command',
113+
'Cake\\Console\\ConsoleOptionParser',
114+
],
115+
}) }}
119116

120117
/**
121-
* {{ name }} command.
122-
*/
118+
* {{ name }} command.
119+
*/
123120
class {{ name }}Command extends Command
124121
{
125122
/**
126-
* Hook method for defining this command's option parser.
127-
*
128-
* @link https://book.cakephp.org/5/en/console-commands/commands.html#defining-arguments-and-options
129-
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
130-
* @return \Cake\Console\ConsoleOptionParser The built parser.
131-
*/
132-
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
123+
* The name of this command.
124+
*
125+
* @var string
126+
*/
127+
protected string $name = 'cake {{ command_name }}';
128+
129+
/**
130+
* Get the default command name.
131+
*
132+
* @return string
133+
*/
134+
public static function defaultName(): string
135+
{
136+
return '{{ command_name }}';
137+
}
138+
139+
/**
140+
* Get the command description.
141+
*
142+
* @return string
143+
*/
144+
public static function getDescription(): string
133145
{
134-
$parser = parent::buildOptionParser($parser);
146+
return 'Command description here.';
147+
}
135148

136-
return $parser;
149+
/**
150+
* Hook method for defining this command's option parser.
151+
*
152+
* @link https://book.cakephp.org/6/en/console-commands/commands.html#defining-arguments-and-options
153+
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
154+
* @return \Cake\Console\ConsoleOptionParser The built parser.
155+
*/
156+
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
157+
{
158+
return parent::buildOptionParser($parser)
159+
->setDescription(static::getDescription());
137160
}
138161

139162
/**
140-
* Implement this method with your command's logic.
141-
*
142-
* @param \Cake\Console\Arguments $args The command arguments.
143-
* @param \Cake\Console\ConsoleIo $io The console io
144-
* @return int|null|void The exit code or null for success
145-
*/
146-
public function execute(Arguments $args, ConsoleIo $io)
163+
* Implement this method with your command's logic.
164+
*
165+
* @return int|null|void The exit code or null for success
166+
*/
167+
public function execute()
147168
{
148169
}
149170
}
150171
```
151172

173+
The `element()` call emits the `<?php declare(strict_types=1);` header, the namespace, and the `use` statements.
174+
Note that commands use `$this->args` and `$this->io` instead of receiving them as `execute()` parameters.
175+
152176
The resultant baked class at `src/Command/FooCommand.php` looks like this:
153177

154178
```php
@@ -158,37 +182,59 @@ declare(strict_types=1);
158182
namespace App\Command;
159183

160184
use Cake\Command\Command;
161-
use Cake\Console\Arguments;
162-
use Cake\Console\ConsoleIo;
163185
use Cake\Console\ConsoleOptionParser;
164186

165187
/**
166-
* Foo command.
167-
*/
188+
* Foo command.
189+
*/
168190
class FooCommand extends Command
169191
{
170192
/**
171-
* Hook method for defining this command's option parser.
172-
*
173-
* @link https://book.cakephp.org/5/en/console-commands/commands.html#defining-arguments-and-options
174-
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
175-
* @return \Cake\Console\ConsoleOptionParser The built parser.
176-
*/
177-
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
193+
* The name of this command.
194+
*
195+
* @var string
196+
*/
197+
protected string $name = 'cake foo';
198+
199+
/**
200+
* Get the default command name.
201+
*
202+
* @return string
203+
*/
204+
public static function defaultName(): string
178205
{
179-
$parser = parent::buildOptionParser($parser);
206+
return 'foo';
207+
}
180208

181-
return $parser;
209+
/**
210+
* Get the command description.
211+
*
212+
* @return string
213+
*/
214+
public static function getDescription(): string
215+
{
216+
return 'Command description here.';
217+
}
218+
219+
/**
220+
* Hook method for defining this command's option parser.
221+
*
222+
* @link https://book.cakephp.org/6/en/console-commands/commands.html#defining-arguments-and-options
223+
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
224+
* @return \Cake\Console\ConsoleOptionParser The built parser.
225+
*/
226+
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
227+
{
228+
return parent::buildOptionParser($parser)
229+
->setDescription(static::getDescription());
182230
}
183231

184232
/**
185-
* Implement this method with your command's logic.
186-
*
187-
* @param \Cake\Console\Arguments $args The command arguments.
188-
* @param \Cake\Console\ConsoleIo $io The console io
189-
* @return int|null|void The exit code or null for success
190-
*/
191-
public function execute(Arguments $args, ConsoleIo $io)
233+
* Implement this method with your command's logic.
234+
*
235+
* @return int|null|void The exit code or null for success
236+
*/
237+
public function execute()
192238
{
193239
}
194240
}
@@ -237,7 +283,7 @@ use Bake\Command\SimpleBakeCommand;
237283

238284
class FooCommand extends SimpleBakeCommand
239285
{
240-
public $pathFragment = 'FooPath/';
286+
public string $pathFragment = 'FooPath/';
241287

242288
public function name(): string
243289
{
@@ -278,26 +324,26 @@ This generates `src/FooPath/ExampleFooOut.php`.
278324
If you also want `bake` to create a test file for your `ExampleFooOut` class, override the `bakeTest()` method in `FooCommand`:
279325

280326
```php
281-
use Cake\Console\Arguments;
282-
use Cake\Console\ConsoleIo;
327+
use Bake\Command\TestCommand;
283328

284-
public function bakeTest(string $className, Arguments $args, ConsoleIo $io): void
329+
public function bakeTest(string $className): void
285330
{
286-
if (!isset($this->Test->classSuffixes[$this->name()])) {
287-
$this->Test->classSuffixes[$this->name()] = 'Foo';
288-
}
289-
290-
$name = ucfirst($this->name());
291-
if (!isset($this->Test->classTypes[$name])) {
292-
$this->Test->classTypes[$name] = 'Foo';
331+
if ($this->args->getOption('no-test')) {
332+
return;
293333
}
294334

295-
parent::bakeTest($className, $args, $io);
335+
$test = new TestCommand();
336+
$test->classSuffixes['Foo'] = 'FooOut';
337+
$test->classTypes['Foo'] = 'FooPath';
338+
$test->plugin = $this->plugin;
339+
$test->setArgs($this->args);
340+
$test->setIo($this->io);
341+
$test->bake('Foo', $className);
296342
}
297343
```
298344

299-
- The **class suffix** is appended to the name provided in your `bake` call. In the example above, that would create `ExampleFooTest.php`.
300-
- The **class type** is the sub-namespace used to reach your file relative to the app or plugin you are baking into. In the example above, that would create the test namespace `App\Test\TestCase\Foo`.
345+
- The **class suffix** is appended to the name provided in your `bake` call. In the example above, that would create `ExampleFooOut` and its test file `tests/TestCase/FooPath/ExampleFooOutTest.php`.
346+
- The **class type** value is the sub-namespace used to reach your file relative to the app or plugin you are baking into. In the example above, that would create the test namespace `App\Test\TestCase\FooPath`.
301347

302348
## Configuring the BakeView Class
303349

‎docs/en/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Before trying to use or extend Bake, make sure it is installed in your applicati
1111
Bake is provided as a plugin that you can install with Composer:
1212

1313
```bash
14-
composer require --dev cakephp/bake:"^3.0"
14+
composer require --dev cakephp/bake:"^4.0"
1515
```
1616

1717
The above installs Bake as a development dependency, so it will not be installed during production deployments.

0 commit comments

Comments
 (0)