@@ -414,7 +414,7 @@ public function getPrimaryKey()
414
414
{
415
415
if ($ this ->_primaryKey === null ) {
416
416
$ schema = $ this ->getSchema ();
417
- $ key = ( array ) $ schema ->primaryKey ();
417
+ $ key = $ schema ->primaryKey ();
418
418
if (count ($ key ) === 1 ) {
419
419
$ key = $ key [0 ];
420
420
}
@@ -886,53 +886,53 @@ public function exists($conditions): bool
886
886
* returns the same resource after a successful save or false in case
887
887
* of any error.
888
888
*
889
- * @param \Cake\Datasource\EntityInterface $resource the resource to be saved
889
+ * @param \Cake\Datasource\EntityInterface $entity the resource to be saved
890
890
* @param array|\ArrayAccess $options The options to use when saving.
891
891
* @return \Cake\Datasource\EntityInterface|false
892
892
*/
893
- public function save (EntityInterface $ resource , $ options = [])
893
+ public function save (EntityInterface $ entity , $ options = [])
894
894
{
895
895
$ options = new ArrayObject ((array )$ options + [
896
896
'checkRules ' => true ,
897
897
'checkExisting ' => false ,
898
898
]);
899
899
900
- if ($ resource ->getErrors ()) {
900
+ if ($ entity ->getErrors ()) {
901
901
return false ;
902
902
}
903
903
904
- if ($ resource ->isNew () === false && !$ resource ->isDirty ()) {
905
- return $ resource ;
904
+ if ($ entity ->isNew () === false && !$ entity ->isDirty ()) {
905
+ return $ entity ;
906
906
}
907
907
908
908
$ primaryColumns = (array )$ this ->getPrimaryKey ();
909
909
910
- if ($ options ['checkExisting ' ] && $ primaryColumns && $ resource ->isNew () && $ resource ->has ($ primaryColumns )) {
910
+ if ($ options ['checkExisting ' ] && $ primaryColumns && $ entity ->isNew () && $ entity ->has ($ primaryColumns )) {
911
911
$ alias = $ this ->getAlias ();
912
912
$ conditions = [];
913
- foreach ($ resource ->extract ($ primaryColumns ) as $ k => $ v ) {
913
+ foreach ($ entity ->extract ($ primaryColumns ) as $ k => $ v ) {
914
914
$ conditions ["$ alias. $ k " ] = $ v ;
915
915
}
916
- $ resource ->setNew (!$ this ->exists ($ conditions ));
916
+ $ entity ->setNew (!$ this ->exists ($ conditions ));
917
917
}
918
918
919
- $ mode = $ resource ->isNew () ? RulesChecker::CREATE : RulesChecker::UPDATE ;
920
- if ($ options ['checkRules ' ] && !$ this ->checkRules ($ resource , $ mode , $ options )) {
919
+ $ mode = $ entity ->isNew () ? RulesChecker::CREATE : RulesChecker::UPDATE ;
920
+ if ($ options ['checkRules ' ] && !$ this ->checkRules ($ entity , $ mode , $ options )) {
921
921
return false ;
922
922
}
923
923
924
- $ event = $ this ->dispatchEvent ('Model.beforeSave ' , compact ('resource ' , 'options ' ));
924
+ $ event = $ this ->dispatchEvent ('Model.beforeSave ' , compact ('entity ' , 'options ' ));
925
925
926
926
if ($ event ->isStopped ()) {
927
927
return $ event ->getResult ();
928
928
}
929
929
930
- $ data = $ resource ->extract ($ this ->getSchema ()->columns (), true );
930
+ $ data = $ entity ->extract ($ this ->getSchema ()->columns (), true );
931
931
932
- if ($ resource ->isNew ()) {
932
+ if ($ entity ->isNew ()) {
933
933
$ query = $ this ->query ()->create ();
934
934
} else {
935
- $ query = $ this ->query ()->update ()->where ($ resource ->extract ($ primaryColumns ));
935
+ $ query = $ this ->query ()->update ()->where ($ entity ->extract ($ primaryColumns ));
936
936
}
937
937
$ query ->set ($ data );
938
938
@@ -941,14 +941,14 @@ public function save(EntityInterface $resource, $options = [])
941
941
return false ;
942
942
}
943
943
944
- if ($ resource ->isNew () && ($ result instanceof EntityInterface)) {
944
+ if ($ entity ->isNew () && ($ result instanceof EntityInterface)) {
945
945
return $ result ;
946
946
}
947
947
948
948
/** @psalm-var class-string<\Cake\Datasource\EntityInterface> $className */
949
- $ className = get_class ($ resource );
949
+ $ className = get_class ($ entity );
950
950
951
- return new $ className ($ resource ->toArray (), [
951
+ return new $ className ($ entity ->toArray (), [
952
952
'markNew ' => false ,
953
953
'markClean ' => true ,
954
954
]);
@@ -957,14 +957,14 @@ public function save(EntityInterface $resource, $options = [])
957
957
/**
958
958
* Delete a single resource.
959
959
*
960
- * @param \Cake\Datasource\EntityInterface $resource The resource to remove.
960
+ * @param \Cake\Datasource\EntityInterface $entity The resource to remove.
961
961
* @param array|\ArrayAccess $options The options for the delete.
962
962
* @return bool
963
963
*/
964
- public function delete (EntityInterface $ resource , $ options = []): bool
964
+ public function delete (EntityInterface $ entity , $ options = []): bool
965
965
{
966
966
$ primaryKeys = (array )$ this ->getPrimaryKey ();
967
- $ values = $ resource ->extract ($ primaryKeys );
967
+ $ values = $ entity ->extract ($ primaryKeys );
968
968
969
969
return (bool )$ this ->query ()->delete ()->where (array_combine ($ primaryKeys , $ values ))->execute ();
970
970
}
0 commit comments