Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TableEventsTrait only #18044

Open
wants to merge 6 commits into
base: 5.next
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add TableEventsTrait only
  • Loading branch information
bancer committed Nov 29, 2024
commit 41af27a3e91a40d29662a40c1b613667c6a9ad2f
206 changes: 206 additions & 0 deletions src/ORM/TableEventsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?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 6.0.0
bancer marked this conversation as resolved.
Show resolved Hide resolved
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\ORM;

use ArrayObject;
use Cake\Database\Query\SelectQuery;
bancer marked this conversation as resolved.
Show resolved Hide resolved
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\Validation\Validator;

/**
* Provides model callbacks.
*/
trait TableEventsTrait
{
/**
* 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

Check warning on line 38 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L38

Added line #L38 was not covered by tests
{
}

Check warning on line 40 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L40

Added line #L40 was not covered by tests

/**
* The Model.afterMarshal event is fired after request data is converted into entities.
* Event handlers will get the converted entities, original request data and the options provided
* to the patchEntity() or newEntity() call.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \Cake\Datasource\EntityInterface $entity The entity to be saved.
* @param \ArrayObject<string, mixed> $data Data to be saved.
* @param \ArrayObject<string, mixed> $options Options.
* @return void
*/
public function afterMarshal(

Check warning on line 53 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L53

Added line #L53 was not covered by tests
EventInterface $event,
EntityInterface $entity,
ArrayObject $data,
ArrayObject $options
): void {
}

Check warning on line 59 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L59

Added line #L59 was not covered by tests

/**
* The Model.buildValidator event is fired when $name validator is created.
* Behaviors, can use this hook to add in validation methods.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \Cake\Validation\Validator $validator Validator.
* @param string $name Name.
* @return void
*/
public function buildValidator(EventInterface $event, Validator $validator, string $name): void

Check warning on line 70 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L70

Added line #L70 was not covered by tests
{
}

Check warning on line 72 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L72

Added line #L72 was not covered by tests

/**
* The Model.beforeFind event is fired before each find operation.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \Cake\Database\Query\SelectQuery $query Query.
bancer marked this conversation as resolved.
Show resolved Hide resolved
* @param \ArrayObject<string, mixed> $options Options.
* @param bool $primary `true` if it is the root query, `false` if it is the associated query.
* @return void
*/
public function beforeFind(EventInterface $event, SelectQuery $query, ArrayObject $options, bool $primary): void

Check warning on line 83 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L83

Added line #L83 was not covered by tests
{
}

Check warning on line 85 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L85

Added line #L85 was not covered by tests

/**
* The Model.beforeSave event is fired before each entity is saved.
* Stopping this event will abort the save operation.
* When the event is stopped the result of the event will be returned.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \Cake\Datasource\EntityInterface $entity The entity to be saved.
* @param \ArrayObject<string, mixed> $options Options.
* @return void
*/
public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options): void

Check warning on line 97 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L97

Added line #L97 was not covered by tests
{
}

Check warning on line 99 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L99

Added line #L99 was not covered by tests

/**
* The Model.afterSave event is fired after an entity is saved.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \Cake\Datasource\EntityInterface $entity Saved entity.
* @param \ArrayObject<string, mixed> $options Options.
* @return void
*/
public function afterSave(EventInterface $event, EntityInterface $entity, ArrayObject $options): void

Check warning on line 109 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L109

Added line #L109 was not covered by tests
{
}

Check warning on line 111 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L111

Added line #L111 was not covered by tests

/**
* The Model.afterSaveCommit event is fired after the transaction in which the save operation is wrapped has been
* committed. It’s also triggered for non atomic saves where database operations are implicitly committed. The event
* is triggered only for the primary table on which save() is directly called. The event is not triggered if a
* transaction is started before calling save.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \Cake\Datasource\EntityInterface $entity Saved entity.
* @param \ArrayObject<string, mixed> $options Options.
* @return void
*/
public function afterSaveCommit(EventInterface $event, EntityInterface $entity, ArrayObject $options): void

Check warning on line 124 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L124

Added line #L124 was not covered by tests
{
}

Check warning on line 126 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L126

Added line #L126 was not covered by tests

/**
* The Model.beforeDelete event is fired before an entity is deleted.
* By stopping this event you will abort the delete operation.
* When the event is stopped the result of the event will be returned.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \Cake\Datasource\EntityInterface $entity Entity to be deleted.
* @param \ArrayObject<string, mixed> $options Options.
* @return void
*/
public function beforeDelete(EventInterface $event, EntityInterface $entity, ArrayObject $options): void

Check warning on line 138 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L138

Added line #L138 was not covered by tests
{
}

Check warning on line 140 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L140

Added line #L140 was not covered by tests

/**
* The Model.afterDelete event is fired after an entity has been deleted.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \Cake\Datasource\EntityInterface $entity Deleted entity.
* @param \ArrayObject<string, mixed> $options Options.
* @return void
*/
public function afterDelete(EventInterface $event, EntityInterface $entity, ArrayObject $options): void

Check warning on line 150 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L150

Added line #L150 was not covered by tests
{
}

Check warning on line 152 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L152

Added line #L152 was not covered by tests

/**
* The Model.afterDeleteCommit event is fired after the transaction in which the delete operation is wrapped has
* been is committed. It’s also triggered for non atomic deletes where database operations are implicitly committed.
* The event is triggered only for the primary table on which delete() is directly called. The event is not
* triggered if a transaction is started before calling delete.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \Cake\Datasource\EntityInterface $entity Deleted entity.
* @param \ArrayObject<string, mixed> $options Options.
* @return void
*/
public function afterDeleteCommit(EventInterface $event, EntityInterface $entity, ArrayObject $options): void

Check warning on line 165 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L165

Added line #L165 was not covered by tests
{
}

Check warning on line 167 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L167

Added line #L167 was not covered by tests

/**
* The Model.beforeRules event is fired before an entity has had rules applied.
* By stopping this event, you can halt the rules checking and set the result of applying rules.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \Cake\Datasource\EntityInterface $entity The entity to be saved.
* @param \ArrayObject<string, mixed> $options Options.
* @param string $operation Operation.
* @return void
*/
public function beforeRules(

Check warning on line 179 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L179

Added line #L179 was not covered by tests
EventInterface $event,
EntityInterface $entity,
ArrayObject $options,
string $operation
): void {
}

Check warning on line 185 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L185

Added line #L185 was not covered by tests

/**
* The Model.afterRules event is fired after an entity has rules applied.
* By stopping this event, you can return the final value of the rules checking operation.
*
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Model event.
* @param \Cake\Datasource\EntityInterface $entity The entity to be saved.
* @param \ArrayObject<string, mixed> $options Options.
* @param bool $result Result.
* @param string $operation Operation.
* @return void
*/
public function afterRules(

Check warning on line 198 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L198

Added line #L198 was not covered by tests
EventInterface $event,
EntityInterface $entity,
ArrayObject $options,
bool $result,
string $operation
): void {
}

Check warning on line 205 in src/ORM/TableEventsTrait.php

View check run for this annotation

Codecov / codecov/patch

src/ORM/TableEventsTrait.php#L205

Added line #L205 was not covered by tests
}