Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/ORM/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use Cake\ORM\Query\SelectQuery;
use Cake\ORM\Query\UpdateQuery;
use Cake\ORM\Rule\IsUnique;
use Cake\ORM\TableEvents\BeforeMarshalEventInterface;
use Cake\Utility\Inflector;
use Cake\Validation\ValidatorAwareInterface;
use Cake\Validation\ValidatorAwareTrait;
Expand Down Expand Up @@ -3191,7 +3192,7 @@ public function validateUnique(mixed $value, array $options, ?array $context = n
public function implementedEvents(): array
{
$eventMap = [
'Model.beforeMarshal' => 'beforeMarshal',
'Model.beforeMarshal' => BeforeMarshalEventInterface::class,
'Model.afterMarshal' => 'afterMarshal',
'Model.buildValidator' => 'buildValidator',
'Model.beforeFind' => 'beforeFind',
Expand All @@ -3206,10 +3207,14 @@ public function implementedEvents(): array
];
$events = [];

foreach ($eventMap as $event => $method) {
foreach ($eventMap as $event => $interface) {
$method = explode('.', $event)[1];
if (!method_exists($this, $method)) {
continue;
}
if (!($this instanceof $interface)) {
throw new CakeException(self::class . ' must implement ' . $interface . ' interface');
}
$events[$event] = $method;
}

Expand Down
32 changes: 32 additions & 0 deletions src/ORM/TableEvents/BeforeMarshalEventInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 5.2.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\ORM\TableEvents;

use ArrayObject;
use Cake\Event\EventInterface;

interface BeforeMarshalEventInterface {
/**
* The Model.beforeMarshal event is fired before request data is converted into entities.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \ArrayObject<string, mixed> $data Data to be saved.
* @param \ArrayObject<string, mixed> $options Options.
* @return void
*/
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options): void;
}