Skip to content

Commit 47cae5a

Browse files
committed
Merge branch '3.x' into 3.next
2 parents 300907a + b1163a5 commit 47cae5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+276
-254
lines changed

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- uses: actions/stale@v9
19+
- uses: actions/stale@v10
2020
with:
2121
repo-token: ${{ secrets.GITHUB_TOKEN }}
2222
stale-issue-message: 'This issue is stale because it has been open for 120 days with no activity. Remove the `stale` label or comment or this will be closed in 15 days'

phpcs.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0"?>
22
<ruleset name="CakePHP Bake">
3-
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />
43
<arg value="ns"/>
54

65
<file>src/</file>

src/Command/PluginCommand.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ public function bake(string $plugin, Arguments $args, ConsoleIo $io): ?bool
125125
$this->_generateFiles($plugin, $this->path, $args, $io);
126126

127127
if (!$this->isVendor) {
128-
$this->_modifyApplication($plugin, $io);
128+
if (!$args->getOption('class-only')) {
129+
$this->_modifyApplication($plugin, $io);
130+
}
129131

130132
$composer = $this->findComposer($args, $io);
131133

@@ -247,6 +249,12 @@ protected function _generateFiles(
247249
}
248250
}
249251

252+
if ($args->getOption('class-only')) {
253+
$files = array_filter($files, function ($file) {
254+
return $file->getFilename() === 'Plugin.php.twig';
255+
});
256+
}
257+
250258
$templates = array_keys($files);
251259
}
252260
} while (!$templates);
@@ -370,6 +378,10 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
370378
->addOption('standalone-path', [
371379
'short' => 'p',
372380
'help' => 'Generate a standalone plugin in the provided path.',
381+
])->addOption('class-only', [
382+
'short' => 'c',
383+
'boolean' => true,
384+
'help' => 'Generate only the plugin class.',
373385
]);
374386

375387
return $parser;

src/Command/TestCommand.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,13 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo
242242
$prefix = $this->getPrefix($args);
243243
$fullClassName = $this->getRealClassName($type, $className, $prefix);
244244

245+
// Check if fixture factories plugin is available
246+
$hasFixtureFactories = $this->hasFixtureFactories();
247+
245248
if (!$args->getOption('no-fixture')) {
246-
if ($args->getOption('fixtures')) {
249+
if ($hasFixtureFactories) {
250+
$io->info('Fixture Factories plugin detected - skipping fixture property generation.');
251+
} elseif ($args->getOption('fixtures')) {
247252
$fixtures = array_map('trim', explode(',', $args->getOption('fixtures')));
248253
$this->_fixtures = array_filter($fixtures);
249254
} elseif ($this->typeCanDetectFixtures($type) && class_exists($fullClassName)) {
@@ -277,6 +282,7 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo
277282
$contents = $this->createTemplateRenderer()
278283
->set('fixtures', $this->_fixtures)
279284
->set('plugin', $this->plugin)
285+
->set('hasFixtureFactories', $hasFixtureFactories)
280286
->set(compact(
281287
'subject',
282288
'className',
@@ -305,6 +311,17 @@ public function bake(string $type, string $className, Arguments $args, ConsoleIo
305311
return false;
306312
}
307313

314+
/**
315+
* Check if the CakePHP Fixture Factories plugin is available
316+
*
317+
* @return bool
318+
*/
319+
protected function hasFixtureFactories(): bool
320+
{
321+
return class_exists('CakephpFixtureFactories\Plugin')
322+
|| class_exists('CakephpFixtureFactories\CakephpFixtureFactoriesPlugin');
323+
}
324+
308325
/**
309326
* Checks whether the chosen type can find its own fixtures.
310327
* Currently only model, and controller are supported

src/Utility/SubsetSchemaCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SubsetSchemaCollection implements CollectionInterface
3333
protected CollectionInterface $collection;
3434

3535
/**
36-
* @var list<string>
36+
* @var array<string>
3737
*/
3838
protected array $tables = [];
3939

src/View/Helper/BakeHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public function columnData(string $field, TableSchema $schema): ?array
304304
public function enumSupportsLabel(string $field, TableSchema $schema): bool
305305
{
306306
$typeName = $schema->getColumnType($field);
307-
if (!str_starts_with($typeName, 'enum-')) {
307+
if (!$typeName || !str_starts_with($typeName, 'enum-')) {
308308
return false;
309309
}
310310
$type = TypeFactory::build($typeName);

templates/bake/Controller/controller.twig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{% endif %}
3333

3434
{%- for component in components %}
35-
{% set classInfo = Bake.classInfo(component, 'Controller/Component', 'Component') %}
35+
{%~ set classInfo = Bake.classInfo(component, 'Controller/Component', 'Component') %}
3636
* @property {{ classInfo.fqn }} ${{ classInfo.name }}
3737
{% endfor %}
3838
*/
@@ -48,20 +48,20 @@ class {{ name }}Controller extends AppController
4848
{
4949
parent::initialize();
5050

51-
{% for component in components %}
51+
{%~ for component in components %}
5252
$this->loadComponent('{{ component }}');
53-
{% endfor %}
54-
{% if helpers %}
53+
{%~ endfor %}
54+
{%~ if helpers %}
5555
$this->viewBuilder()->setHelpers({{ Bake.exportArray(helpers)|raw }});
56-
{% endif %}
57-
{% if has_login %}
56+
{%~ endif %}
57+
{%~ if has_login %}
5858
$this->Authentication->allowUnauthenticated(['login']);
59-
{% endif %}
59+
{%~ endif %}
6060
}
61-
{% if actions|length %}{{ "\n" }}{% endif %}
61+
{%~ if actions|length %}{{ "\n" }}{% endif %}
6262
{% endif %}
63-
{%- for action in actions %}
64-
{% if loop.index > 1 %}{{ "\n" }}{% endif %}
63+
{% for action in actions %}
64+
{%~ if loop.index > 1 %}{{ "\n" }}{% endif %}
6565
{{- element('Bake.Controller/' ~ action) -}}
6666
{% endfor %}
6767
}

templates/bake/Model/entity.twig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
{% set annotations = DocBlock.propertyHints(propertyHintMap) %}
1919

2020
{%- if associationHintMap %}
21-
{%- set annotations = annotations|merge(['']) %}
22-
{%- set annotations = annotations|merge(DocBlock.propertyHints(associationHintMap)) %}
21+
{%~ set annotations = annotations|merge(['']) %}
22+
{%~ set annotations = annotations|merge(DocBlock.propertyHints(associationHintMap)) %}
2323
{% endif %}
2424

2525
{%- set accessible = Bake.getFieldAccessibility(fields, primaryKey) %}
@@ -39,7 +39,7 @@ class {{ name }} extends Entity{{ fileBuilder.classBuilder.implements ? ' implem
3939

4040
{% endif %}
4141
{% if accessible %}
42-
{%- set generatedProperties = generatedProperties|merge(['_accessible']) %}
42+
{%~ set generatedProperties = generatedProperties|merge(['_accessible']) %}
4343
/**
4444
* Fields that can be mass assigned using newEntity() or patchEntity().
4545
*
@@ -54,12 +54,12 @@ class {{ name }} extends Entity{{ fileBuilder.classBuilder.implements ? ' implem
5454
{% if accessible and hidden %}
5555

5656
{% endif %}
57-
{%- if hidden %}
58-
{%- set generatedProperties = generatedProperties|merge(['_hidden']) %}
57+
{% if hidden %}
58+
{%~ set generatedProperties = generatedProperties|merge(['_hidden']) %}
5959
/**
6060
* Fields that are excluded from JSON versions of the entity.
6161
*
62-
* @var list<string>
62+
* @var array<string>
6363
*/
6464
protected array $_hidden = {{ Bake.exportVar(hidden, 1)|raw }};
6565
{% endif %}

templates/bake/Model/table.twig

Lines changed: 45 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -50,58 +50,43 @@ class {{ name }}Table extends Table{{ fileBuilder.classBuilder.implements ? ' im
5050
{%- if displayField %}
5151
$this->setDisplayField({{ (displayField is iterable ? Bake.exportArray(displayField) : Bake.exportVar(displayField))|raw }});
5252
{% endif %}
53-
54-
{%- if primaryKey %}
55-
{%- if primaryKey is iterable and primaryKey|length > 1 %}
53+
{% if primaryKey %}
54+
{%~ if primaryKey is iterable and primaryKey|length > 1 %}
5655
$this->setPrimaryKey({{ Bake.exportArray(primaryKey)|raw }});
57-
{{- "\n" }}
58-
{%- else %}
56+
{%~ else %}
5957
$this->setPrimaryKey('{{ primaryKey|as_array|first }}');
60-
{{- "\n" }}
61-
{%- endif %}
58+
{%~ endif %}
6259
{% endif %}
60+
{% if enums %}
6361

64-
{%- if enums %}
65-
66-
{% endif %}
67-
68-
{%- if enums %}
69-
70-
{%- for name, className in enums %}
62+
{%~ for name, className in enums %}
7163
$this->getSchema()->setColumnType('{{ name }}', \Cake\Database\Type\EnumType::from(\{{ className }}::class));
72-
{% endfor %}
64+
{%~ endfor %}
7365
{% endif %}
66+
{% if behaviors %}
7467

75-
{%- if behaviors %}
76-
77-
{% endif %}
78-
79-
{%- for behavior, behaviorData in behaviors %}
68+
{%~ for behavior, behaviorData in behaviors %}
8069
$this->addBehavior('{{ behavior }}'{{ (behaviorData ? (", " ~ Bake.exportArray(behaviorData, 2)|raw ~ '') : '')|raw }});
81-
{% endfor %}
82-
83-
{%- if associations.belongsTo or associations.hasMany or associations.belongsToMany %}
84-
70+
{%~ endfor %}
8571
{% endif %}
86-
87-
{%- for type, assocs in associations %}
88-
{%- for assoc in assocs %}
89-
{%- set assocData = [] %}
90-
{%- for key, val in assoc %}
91-
{%- if key is not same as('alias') %}
92-
{%- set assocData = assocData|merge({(key): val}) %}
93-
{%- endif %}
94-
{%- endfor %}
72+
{% if associations.belongsTo or associations.hasMany or associations.belongsToMany %}
73+
74+
{%~ for type, assocs in associations %}
75+
{%~ for assoc in assocs %}
76+
{%~ set assocData = [] %}
77+
{%~ for key, val in assoc %}
78+
{%~ if key is not same as('alias') %}
79+
{%~ set assocData = assocData|merge({(key): val}) %}
80+
{%~ endif %}
81+
{%~ endfor %}
9582
$this->{{ type }}('{{ assoc.alias }}', {{ Bake.exportArray(assocData, 2)|raw }});
96-
{{- "\n" }}
97-
{%- endfor %}
98-
{% endfor %}
83+
{%~ endfor %}
84+
{%~ endfor %}
85+
{% endif %}
9986
}
100-
{{- "\n" }}
101-
102-
{%- if validation %}
103-
{% set generatedFunctions = generatedFunctions|merge(['validationDefault']) %}
87+
{% if validation %}
10488

89+
{%~ set generatedFunctions = generatedFunctions|merge(['validationDefault']) %}
10590
/**
10691
* Default validation rules.
10792
*
@@ -110,25 +95,24 @@ class {{ name }}Table extends Table{{ fileBuilder.classBuilder.implements ? ' im
11095
*/
11196
public function validationDefault(Validator $validator): Validator
11297
{
113-
{% for field, rules in validation %}
114-
{% set validationMethods = Bake.getValidationMethods(field, rules) %}
115-
{% if validationMethods %}
98+
{%~ for field, rules in validation %}
99+
{%~ set validationMethods = Bake.getValidationMethods(field, rules) %}
100+
{%~ if validationMethods %}
116101
$validator
117-
{% for validationMethod in validationMethods %}
118-
{% if loop.last %}
119-
{% set validationMethod = validationMethod ~ ';' %}
120-
{% endif %}
102+
{%~ for validationMethod in validationMethods %}
103+
{%~ if loop.last %}
104+
{%~ set validationMethod = validationMethod ~ ';' %}
105+
{%~ endif %}
121106
{{ validationMethod|raw }}
122-
{% endfor %}
107+
{%~ endfor %}
123108

124-
{% endif %}
125-
{% endfor %}
109+
{%~ endif %}
110+
{%~ endfor %}
126111
return $validator;
127112
}
128113
{% endif %}
129-
130114
{%- if rulesChecker %}
131-
{% set generatedFunctions = generatedFunctions|merge(['buildRules']) %}
115+
{%~ set generatedFunctions = generatedFunctions|merge(['buildRules']) %}
132116

133117
/**
134118
* Returns a rules checker object that will be used for validating
@@ -139,21 +123,20 @@ class {{ name }}Table extends Table{{ fileBuilder.classBuilder.implements ? ' im
139123
*/
140124
public function buildRules(RulesChecker $rules): RulesChecker
141125
{
142-
{% for rule in rulesChecker %}
143-
{% set fields = Bake.exportArray(rule.fields) %}
144-
{% set options = '' %}
145-
{% for optionName, optionValue in rule.options %}
146-
{%~ set options = (loop.first ? '[' : options) ~ "'#{optionName}' => " ~ Bake.exportVar(optionValue) ~ (loop.last ? ']' : ', ') %}
147-
{% endfor %}
126+
{%~ for rule in rulesChecker %}
127+
{%~ set fields = Bake.exportArray(rule.fields) %}
128+
{%~ set options = '' %}
129+
{%~ for optionName, optionValue in rule.options %}
130+
{%~ set options = (loop.first ? '[' : options) ~ "'#{optionName}' => " ~ Bake.exportVar(optionValue) ~ (loop.last ? ']' : ', ') %}
131+
{%~ endfor %}
148132
$rules->add($rules->{{ rule.name }}({{ fields|raw }}{{ (rule.extra|default ? ", '#{rule.extra}'" : '')|raw }}{{ (options ? ', ' ~ options : '')|raw }}), ['errorField' => '{{ rule.fields[0] }}']);
149-
{% endfor %}
133+
{%~ endfor %}
150134

151135
return $rules;
152136
}
153137
{% endif %}
154-
155-
{%- if connection is not same as('default') %}
156-
{% set generatedFunctions = generatedFunctions|merge(['defaultConnectionName']) %}
138+
{% if connection is not same as('default') %}
139+
{%~ set generatedFunctions = generatedFunctions|merge(['defaultConnectionName']) %}
157140

158141
/**
159142
* Returns the database connection name to use by default.

templates/bake/Template/add.twig

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@
1717
/**
1818
* @var \{{ namespace }}\View\AppView $this
1919
* @var \{{ entityClass }} ${{ singularVar }}
20-
{{- "\n" }}
21-
{%- if associations.BelongsTo is defined %}
22-
{%- for assocName, assocData in associations.BelongsTo %}
20+
{% if associations.BelongsTo is defined %}
21+
{%~ for assocName, assocData in associations.BelongsTo %}
2322
* @var \Cake\Collection\CollectionInterface|string[] ${{ assocData.variable }}
24-
{{- "\n" }}
25-
{%- endfor %}
23+
{%~ endfor %}
2624
{% endif %}
27-
{%- if associations.BelongsToMany is defined %}
28-
{%- for assocName, assocData in associations.BelongsToMany %}
25+
{% if associations.BelongsToMany is defined %}
26+
{%~ for assocName, assocData in associations.BelongsToMany %}
2927
* @var \Cake\Collection\CollectionInterface|string[] ${{ assocData.variable }}
30-
{{- "\n" }}
31-
{%- endfor %}
28+
{%~ endfor %}
3229
{% endif %}
3330
*/
3431
?>

0 commit comments

Comments
 (0)