CakePHP plugin to "shim" functionality up and down for major versions of the framework.
MIT License
Published by dereuromark over 4 years ago
Shim.Nullable
behavior can now also run on beforeSave()
callback instead of beforeMarshal()
.
This helps with validation that needs to have the empty string posted still available for isset()
checks and alike.
Also, that callback can be used specifically on "dirty" fields.
You can also refactor those to array_key_exists()
, if you want to keep the default event and expect nullish input.
Published by dereuromark almost 5 years ago
The tool to help ease migration coming from CakePHP 3.x apps.
Then you can slowly start refactoring again further while the app is already running again.
Feel free to contribute more shims to either CakePHP 3.x or 4.x version branch.
Published by dereuromark almost 5 years ago
Please help to finalize for stable release.
Published by dereuromark almost 5 years ago
CakePHP 2.x maintenance release.
Published by dereuromark almost 5 years ago
An Inflector backport has been added as an opt-in replacement for the core one.
Its Inflector::pluralize()
already uses new 4.x behavior:
pluralize()
: index
=> indexes
(instead of indices
)You can also configure the core one with custom inflections from your bootstrap, though.
Published by dereuromark about 5 years ago
E_USER_*
type if needed).Shim.deprecations
set to true
. You can also silence specific deprecations.newEntity()
vs newEmptyEntity()
.Published by dereuromark about 5 years ago
Add more 4.x shims:
Controller::referer()
now defaults to true for internal referer only (as per 4.x default).Published by dereuromark over 5 years ago
Allow CastTrait to handle empty strings.
This is mainly important when handling request data in controller, as they can be empty strings coming from either data or query.
Published by dereuromark over 5 years ago
This is useful if you want to get your CakePHP 3 plugins to PHPStan level 7 on controller level, as the query input needs to be properly asserted/cast depending on if it is optional or required input (nullable or not).
Published by dereuromark over 5 years ago
Add read()
method for entities to allow dot syntax convenience access.
$entity->read('tags.0.name')
will return the property if it exists or returns null otherwise.
This compliments the getOrFail()
part which does the opposite (guarantees the path to be present).
Published by dereuromark over 5 years ago
Allow adding get...OrFail()
methods to Entity classes to have non-nullable return values asserted.
This is needed for chaining, as null-pointer-occurrences should be avoided here.
Just use the trait here:
use Shim\Model\Entity\GetTrait;
class Post extends Entity {
use GetTrait;
...
}
It automatically provides the getters here for you.
// bad (tag could be null)
$tagName = $entity->tag->name;
// good (tag cannot be null as this would throw clear exception)
$tagName = $entity->getOrFail('tag')->name;
This will please both analyzers and IDE as well as throw meaningful exceptions in case the field is not set in the entity as expected in this particular case.
For all nullable cases you can still use the normal property access, of course.
Pro tip: Use the included IdeHelper EntityAnnotator replacement to allow annotations to be added for all of your entities' fields.
/**
* @property int $id
* @property string $title
* @property \Cake\I18n\FrozenTime|null $created
* @property \Tags\Model\Entity\Tag|null $tag
* @method int getIdOrFail()
* @method string getTitleOrFail()
* @method \Cake\I18n\FrozenTime getCreatedOrFail()
* @method \Tags\Model\Entity\Tag getTagOrFail()
*/
class Post extends Entity {
...
}
Published by dereuromark almost 6 years ago
Small NullableBehavior fix for nullable foreign keys.
Published by dereuromark almost 6 years ago
CakePHP 3.6+ from now on.
Published by dereuromark over 6 years ago
CakePHP 2.x maintenance release.
Configure::write('Shim.warnAboutBindModelMethod', true);
added to warn you about the usage of bindModel()
method.Configure::write('Shim.warnAboutValidateProperty', true);
added to warn you if Model::$validate was set as a class property.Shim.Tree
behavior fixed upPublished by dereuromark over 6 years ago
CakePHP 2.x maintenance release.
Added 'Shim.warnAboutRelationProperty'
Backported validationDefault() method
Fixed some small issues
Published by dereuromark over 6 years ago
Included commits: https://github.com/dereuromark/cakephp-shim/compare/1.6.1...1.7.0
CakePHP 3.6 compatibility.
The plugin now also is CakePHP 3.5+.
Published by dereuromark over 6 years ago
Backported Table::addAssociations()
Published by dereuromark almost 7 years ago
Small validation shim fix for simple string validation rules.
Published by dereuromark almost 7 years ago
'null'
).Note: This version now requires CakePHP 3.4+
Published by dereuromark almost 7 years ago
Small 2.x fixes.