Skip to content

Configuration ​

Configure the plugin under CakeDto, not Dto. Copy only the settings you need into config/app.php or use Configure::write() during bootstrap. The example configuration lists the plugin options.

php
'CakeDto' => [
    'strictTypes' => true,
    'immutable' => false,
],

Generation settings take effect after regeneration; they do not change already generated classes.

SettingDefaultPurpose
engineXmlEngineDefinition parser implementing EngineInterface.
suffixDtoGenerated class suffix. An empty string removes it; avoid reserved PHP class names.
srcPathApplication or plugin src/Application output root. The generator adds a Dto/ subdirectory; plugin generation uses its own src/.
strictTypesfalseAdd declare(strict_types=1) to generated files. PHP scalar coercion also depends on the calling file's strict-types setting.
scalarAndReturnTypestrueGenerate scalar parameter and return declarations.
typedConstantsfalseUse typed class constants. Enable only when the runtime is PHP 8.3 or newer.
immutablefalseDefault immutability for definitions without an explicit setting.
defaultCollectionType\ArrayObjectDefault generated collection type.
debugfalseInclude additional definition metadata in generated DTOs.
assocKeyFieldsslug, login, name, idCandidate string keys when inferring associative collections from example JSON.
databaseTypeMapImporter defaultsOverride database-to-DTO type mappings entry by entry.
adminAccessUnset, denyClosure that must return literal true for access to importer pages.
finderLibrary FinderDefinition file finder.
builderPlugin BuilderClass that builds definitions.
generatorPlugin GeneratorClass that writes generated PHP.
rendererPlugin RendererClass that renders generation templates.

Nullable override settings such as engine and builder use their default class when unset or null. defaultCollectionType also uses its default when null.

Separate generated code ​

php
'CakeDto' => [
    'srcPath' => ROOT . DS . 'generated' . DS,
],

This writes application DTOs into generated/Dto/. With --plugin, the generator uses that plugin's src/Dto/ instead; an application output override never redirects plugin classes into the same directory.

Add a matching Composer autoload entry alongside your existing application mapping:

json
{
  "autoload": {
    "psr-4": {
      "App\\": "src/",
      "App\\Dto\\": "generated/Dto/"
    }
  }
}

Then refresh the autoloader:

sh
composer dump-autoload

Changing the output directory does not change the generated namespace. Use App.namespace, a definition's nested name, or --namespace for that.

Runtime defaults ​

The underlying library also provides runtime settings:

php
use PhpCollective\Dto\Dto\Dto;

Dto::setDefaultKeyType(Dto::TYPE_UNDERSCORED);

The plugin sets the library's collection factory to create Cake\Collection\Collection instances and registers the CakePHP collection adapter during bootstrap. This does not change the generated defaultCollectionType from \ArrayObject; that is a separate generation setting.

PHP compatibility ​

The default generated syntax supports the package's minimum PHP version. Typed constants require a newer runtime and are opt-in. Check generated output with --confirm under the PHP version used by your application, especially after changing templates or generation settings.

See the parent library documentation for shared DTO behavior and configuration beyond this CakePHP integration.