Skip to content
Merged

Cake 6 #1102

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- 2.next
- 3.x
- 3.next
- 4.x
pull_request:
branches:
- '*'
Expand All @@ -17,9 +18,9 @@ permissions:

jobs:
testsuite:
uses: cakephp/.github/.github/workflows/testsuite-with-db.yml@5.x
uses: cakephp/.github/.github/workflows/testsuite-with-db.yml@6.x
secrets: inherit

cs-stan:
uses: cakephp/.github/.github/workflows/cs-stan.yml@5.x
uses: cakephp/.github/.github/workflows/cs-stan.yml@6.x
secrets: inherit
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bake plugin for CakePHP

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

## Documentation

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

## Testing

Expand Down
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
"source": "https://github.com/cakephp/bake"
},
"require": {
"php": ">=8.2",
"php": ">=8.4",
"brick/varexporter": "^0.7.0",
"cakephp/cakephp": "^5.4",
"cakephp/twig-view": "^2.1",
"cakephp/cakephp": "^6.0",
"cakephp/twig-view": "^3.0",
"nikic/php-parser": "^5.0.0"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^5.0.0",
"cakephp/debug_kit": "^5.0.0",
"phpunit/phpunit": "^11.5.20 || ^12.2.4 || ^13.0"
"cakephp/cakephp-codesniffer": "^6.0",
"cakephp/debug_kit": "^6.0",
"phpunit/phpunit": "^12.2.4 || ^13.0"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -71,10 +71,12 @@
"stan": "@phpstan",
"stan-baseline": "tools/phpstan --generate-baseline",
"stan-setup": "phive install",
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.3.1\" && mv composer.backup composer.json",
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.6.0\" && mv composer.backup composer.json",
"rector-check": "vendor/bin/rector process --dry-run",
"rector-fix": "vendor/bin/rector process",
"test": "phpunit",
"test-coverage": "phpunit --coverage-clover=clover.xml"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
11 changes: 6 additions & 5 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const tocPt = require('./toc_pt.json')
const tocRu = require('./toc_ru.json')

const versions = {
text: '3.x',
text: '4.x',
items: [
{ text: '3.x (current)', link: 'https://book.cakephp.org/bake/3/', target: '_self' },
{ text: '4.x (current)', link: 'https://book.cakephp.org/bake/4/', target: '_self' },
{ text: '3.x', link: 'https://book.cakephp.org/bake/3/', target: '_self' },
{ text: '2.x', link: 'https://book.cakephp.org/bake/2.x/', target: '_self' },
{ text: '1.x', link: 'https://book.cakephp.org/bake/1.x/', target: '_self' },
],
Expand All @@ -23,12 +24,12 @@ export default {
srcDir: '.',
title: 'Bake',
description: 'CakePHP Bake Documentation',
base: '/bake/3/',
base: '/bake/4/',
rewrites: {
'en/:slug*': ':slug*',
},
sitemap: {
hostname: 'https://book.cakephp.org/bake/3/',
hostname: 'https://book.cakephp.org/bake/4/',
},
themeConfig: {
siteTitle: false,
Expand All @@ -37,7 +38,7 @@ export default {
{ icon: 'github', link: 'https://github.com/cakephp/bake' },
],
editLink: {
pattern: 'https://github.com/cakephp/bake/edit/3.x/docs/:path',
pattern: 'https://github.com/cakephp/bake/edit/4.x/docs/:path',
text: 'Edit this page on GitHub',
},
sidebar: tocEn,
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/toc_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"items": [
{ "text": "Consola Bake", "link": "/es/" },
{ "text": "Crear código con Bake", "link": "/es/usage" },
{ "text": "Extending Bake", "link": "/es/development" }
{ "text": "Extender Bake", "link": "/es/development" }
]
}
]
Expand Down
170 changes: 108 additions & 62 deletions docs/en/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ For instance, if you want to add specific actions to your `UsersController` when
<?php
use Cake\Event\EventInterface;
use Cake\Event\EventManager;
use Cake\Utility\Hash;

// in src/Application::bootstrapCli()

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

```php
<?php
declare(strict_types=1);

namespace {{ namespace }}\Command;

use Cake\Command\Command;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
{{ element('Bake.file_header', {
namespace: "#{namespace}\\Command",
classImports: [
'Cake\\Command\\Command',
'Cake\\Console\\ConsoleOptionParser',
],
}) }}

/**
* {{ name }} command.
*/
* {{ name }} command.
*/
class {{ name }}Command extends Command
{
/**
* Hook method for defining this command's option parser.
*
* @link https://book.cakephp.org/5/en/console-commands/commands.html#defining-arguments-and-options
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
* @return \Cake\Console\ConsoleOptionParser The built parser.
*/
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
* The name of this command.
*
* @var string
*/
protected string $name = 'cake {{ command_name }}';

/**
* Get the default command name.
*
* @return string
*/
public static function defaultName(): string
{
return '{{ command_name }}';
}

/**
* Get the command description.
*
* @return string
*/
public static function getDescription(): string
{
$parser = parent::buildOptionParser($parser);
return 'Command description here.';
}

return $parser;
/**
* Hook method for defining this command's option parser.
*
* @link https://book.cakephp.org/6/en/console-commands/commands.html#defining-arguments-and-options
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
* @return \Cake\Console\ConsoleOptionParser The built parser.
*/
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
return parent::buildOptionParser($parser)
->setDescription(static::getDescription());
}

/**
* Implement this method with your command's logic.
*
* @param \Cake\Console\Arguments $args The command arguments.
* @param \Cake\Console\ConsoleIo $io The console io
* @return int|null|void The exit code or null for success
*/
public function execute(Arguments $args, ConsoleIo $io)
* Implement this method with your command's logic.
*
* @return int|null|void The exit code or null for success
*/
public function execute()
{
}
}
```

The `element()` call emits the `<?php declare(strict_types=1);` header, the namespace, and the `use` statements.
Note that commands use `$this->args` and `$this->io` instead of receiving them as `execute()` parameters.

The resultant baked class at `src/Command/FooCommand.php` looks like this:

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

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

/**
* Foo command.
*/
* Foo command.
*/
class FooCommand extends Command
{
/**
* Hook method for defining this command's option parser.
*
* @link https://book.cakephp.org/5/en/console-commands/commands.html#defining-arguments-and-options
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
* @return \Cake\Console\ConsoleOptionParser The built parser.
*/
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
* The name of this command.
*
* @var string
*/
protected string $name = 'cake foo';

/**
* Get the default command name.
*
* @return string
*/
public static function defaultName(): string
{
$parser = parent::buildOptionParser($parser);
return 'foo';
}

return $parser;
/**
* Get the command description.
*
* @return string
*/
public static function getDescription(): string
{
return 'Command description here.';
}

/**
* Hook method for defining this command's option parser.
*
* @link https://book.cakephp.org/6/en/console-commands/commands.html#defining-arguments-and-options
* @param \Cake\Console\ConsoleOptionParser $parser The parser to be defined
* @return \Cake\Console\ConsoleOptionParser The built parser.
*/
public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
return parent::buildOptionParser($parser)
->setDescription(static::getDescription());
}

/**
* Implement this method with your command's logic.
*
* @param \Cake\Console\Arguments $args The command arguments.
* @param \Cake\Console\ConsoleIo $io The console io
* @return int|null|void The exit code or null for success
*/
public function execute(Arguments $args, ConsoleIo $io)
* Implement this method with your command's logic.
*
* @return int|null|void The exit code or null for success
*/
public function execute()
{
}
}
Expand Down Expand Up @@ -237,7 +283,7 @@ use Bake\Command\SimpleBakeCommand;

class FooCommand extends SimpleBakeCommand
{
public $pathFragment = 'FooPath/';
public string $pathFragment = 'FooPath/';

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

```php
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Bake\Command\TestCommand;

public function bakeTest(string $className, Arguments $args, ConsoleIo $io): void
public function bakeTest(string $className): void
{
if (!isset($this->Test->classSuffixes[$this->name()])) {
$this->Test->classSuffixes[$this->name()] = 'Foo';
}

$name = ucfirst($this->name());
if (!isset($this->Test->classTypes[$name])) {
$this->Test->classTypes[$name] = 'Foo';
if ($this->args->getOption('no-test')) {
return;
}

parent::bakeTest($className, $args, $io);
$test = new TestCommand();
$test->classSuffixes['Foo'] = 'FooOut';
$test->classTypes['Foo'] = 'FooPath';
$test->plugin = $this->plugin;
$test->setArgs($this->args);
$test->setIo($this->io);
$test->bake('Foo', $className);
}
```

- The **class suffix** is appended to the name provided in your `bake` call. In the example above, that would create `ExampleFooTest.php`.
- 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`.
- 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`.
- 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`.

## Configuring the BakeView Class

Expand Down
2 changes: 1 addition & 1 deletion docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Before trying to use or extend Bake, make sure it is installed in your applicati
Bake is provided as a plugin that you can install with Composer:

```bash
composer require --dev cakephp/bake:"^3.0"
composer require --dev cakephp/bake:"^4.0"
```

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