Skip to content

Overview ​

The Shim plugin "shims" functionality up and down across CakePHP major versions. It also provides a handful of small, app-friendly convenience wrappers.

This is mainly useful when upgrading large applications to the next major framework version. A lot of code usually needs to be adjusted; with this plugin fewer lines need to be touched. Especially the ORM layer, which would otherwise require heavy refactoring, needs far fewer changes to get things working again.

Zero-dependency plugin

Apart from the framework core, this plugin has no other dependencies. It is used one piece at a time. Classes and plugin aliases work without registration. Loading Shim additionally runs its bootstrap.

CakePHP version

This documentation is for the branch that shims 4.x in 5.x for applications running CakePHP 5. For older releases, see the version map.

How it works ​

Choose the functionality you need. For most cases you do not even need to load the plugin. The individual elements (database types, traits, behaviors, helpers) can be used directly where needed.

There are two broad categories of shims:

  • Main shims: convenience functionality that will most likely be ported forward into future releases. Review their API when moving to a new major version.
  • BC shims: backwards-compatibility helpers that only exist to ease the 3.x → 4.x → 5.x transition. These are intended to be removed again once your upgrade is complete.

Use BC shims deliberately

Using backwards-compatibility shims on purpose in new code is usually a bad idea. They exist to keep an in-flight upgrade running, not to be a permanent crutch.

The pieces ​

AreaWhat the shim provides
DatabaseCustom column types: UUID (binary), time-as-string, year, and array.
DatasourceA paginator that still understands contain/conditions, plus loadModel() shimming.
ModelA base Table re-using legacy properties, entity read/require/get-set traits, and a Nullable behavior.
ControllerA base Controller, the CastTrait, and an out-of-bounds pagination redirect trait.
ComponentA RequestHandler component for continued automatic view-class switching.
ViewConfigure, Cookie, and Number helpers.
UtilityInflector::slug() BC wrapper.
TestingA TestTrait, ConsoleOutput, and integration/test case base classes.

Next steps ​

When planning an upgrade, also look into the official upgrade docs and the linked upgrade tool. They contain many more ideas on how to align code with the current direction of the framework and reduce friction long term. See also the blog post on the CakePHP 5 upgrade guide.

A full overview of all shimming between versions can be found in the Wiki.

Released under the MIT License.