Published by dereuromark about 6 years ago
Fixed the pivot relation from BelongsToMany to the correct one (HasMany):
* @property \App\Model\Table\FeaturesFeaturesTable|\Cake\ORM\Association\HasMany $FeaturesFeatures
* @property \App\Model\Table\FeaturesModulesTable|\Cake\ORM\Association\HasMany $FeaturesModules
*/
class FeaturesTable extends Table
HABTM is always 2x hasMany from the outside in and 2x belongsTo from the inside out.
Published by dereuromark about 6 years ago
For BelongsToMany relationships this will add typehinting/clickability for the pivot table and its Table class:
// FeaturesTable
$this->belongsToMany('DependingFeatures', [
'foreignKey' => 'feature_id',
'className' => 'Features',
'targetForeignKey' => 'depending_feature_id',
'joinTable' => 'features_features',
'propertyName' => 'depending_features',
]);
$this->belongsToMany('Modules', [
'foreignKey' => 'feature_id',
'targetForeignKey' => 'module_id',
'through' => 'FeaturesModules',
'joinTable' => 'features_modules',
'propertyName' => 'modules',
]);
now adds
* @property \App\Model\Table\FeaturesFeaturesTable|\Cake\ORM\Association\HasMany $FeaturesFeatures
* @property \App\Model\Table\FeaturesModulesTable|\Cake\ORM\Association\HasMany $FeaturesModules
*/
class FeaturesTable extends Table
or at least basic Cake\ORM\Table class for chaining and querying on the pivot table as in
$this->Features->FeaturesModules->find()->contain(['Modules', 'Features']);
// or
$this->Features->FeaturesFeatures->find()->contain(['DependingFeatures', 'Features']);
Note one time through and one time auto-calculation alias.
Published by dereuromark about 6 years ago
Table behaviors and generic model code use the following signature:
/**
* @param \Cake\Event\Event $event Event
* @param \Cake\Datasource\EntityInterface $entity Entity
* @param \ArrayObject $options Options
* @return void
*/
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)
And as long you only use methods and attributes of the EntityInterface (as contracted here), this is fine.
But in specific Table class code, you usually also access the entities' concrete properties.
Here using this typehint is somewhat a lie. To please IDE and tooling like PHPStan we can at least fix up the doc block, however.
And that is what this task is doing, declaring the concrete entity to be available and used inside.
Inside the concrete PostsTable after running the callbacks
command:
/**
* @param \Cake\Event\Event $event Event
* @param \App\Model\Entity\Post $entity Entity
* @param \ArrayObject $options Options
* @return void
*/
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)
The tooling now knows to expect the apps' Post entity and its methods/properties to be available.
You can also add your own tasks into the collection to make certain changes for other CakePHP callbacks. See docs for details.
Published by dereuromark about 6 years ago
Fix classes annotation inside subfolders.
Published by dereuromark about 6 years ago
Added Query::find() auto-complete besides the existing Table::find(), e.g. in callbacks:
$searchManager
->callback('tag', [
'callback' => function (QueryInterface $query, array $args) {
$query->find('tagged', $args);
}
]);
The tagged
finder would be autocompleted now.
Here is an example in PHPStorm:
In order to run certain "fixers" over all classes, class annotations and their tasks are now available.
Out of the box it will already ship with one: ModelAware annotating.
Inside any non-ORM business logic class, e.g. Service/FooBar layer:
$this->loadModel('Posts');
automatically annotates
@property \App\Model\Table\PostsTable $Posts
above the class then.
This does, however, impact existing ones in terms of -r (remove) cleanup option as it is not completely in sync.
So use this only without the -r option for now.
Published by dereuromark over 6 years ago
Included commits: https://github.com/dereuromark/cakephp-ide-helper/compare/0.11.2...0.12.0
CakePHP 3.6+ support
It can, however, be still necessary to set your error level to E_ALL & ~E_USER_DEPRECATED
in your app.php config.
Note: squizlabs/php_codesniffer ^2.8 has been dropped in favor of ^3.0 only.
Published by dereuromark over 6 years ago
Use the configured application namespace.
Published by dereuromark over 6 years ago
Fixed element names for Windows OS users. The slashes inside element names are always forward /
(and are not DS at this point).
Published by dereuromark over 6 years ago
New auto-complete functionality for element() usage in templates:
No more typing of the full file name necessary, it will even find your plugin's elements or nested ones.
Demo: https://streamable.com/ixrbg
CakePHP 3.5 and 3.6 are only supported from here on.
This is necessary as 3.4 does not fully work with PHP7.2+, and otherwise testing compatibility is difficult.
Make sure you upgraded to at least 3.5 already.
Published by dereuromark over 6 years ago
Published by dereuromark almost 7 years ago
Published by dereuromark almost 7 years ago
Allow plugin controllers to be annotated with their plugin models.
Published by dereuromark almost 7 years ago
Also allow namespaced plugins to be annotated correctly.
Published by dereuromark almost 7 years ago
Allow dynamically loaded behaviors to be annotated in Table classes.
Published by dereuromark almost 7 years ago
Published by dereuromark almost 7 years ago
Allow database Type auto-complete.
Published by dereuromark about 7 years ago
Published by dereuromark about 7 years ago
Published by dereuromark about 7 years ago
Published by dereuromark about 7 years ago
Vendor/PluginName.ModelName
syntax now works.-f
/--filter
option for AnnotationsShell to more quickly annotate specific new files.