-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
205 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\Mock\EntitiesWithHooks; | ||
|
||
use Zrnik\MkSQL\Repository\Attributes\ColumnType; | ||
use Zrnik\MkSQL\Repository\Attributes\PrimaryKey; | ||
use Zrnik\MkSQL\Repository\Attributes\TableName; | ||
use Zrnik\MkSQL\Repository\BaseEntity; | ||
|
||
#[TableName('hook_test_AfterRetrieveHookEntity')] | ||
class AfterRetrieveHookEntity extends BaseEntity | ||
{ | ||
#[PrimaryKey] | ||
public ?int $id = null; | ||
|
||
#[ColumnType('varchar(100)')] | ||
public string $afterSaveException = 'Hello World'; | ||
|
||
/** | ||
* @throws EntityWithHookException | ||
* @noinspection PhpMissingParentCallCommonInspection | ||
*/ | ||
public function afterRetrieve(): void | ||
{ | ||
throw new EntityWithHookException(EntityHookExceptionType::AFTER_RETRIEVE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\Mock\EntitiesWithHooks; | ||
|
||
use Zrnik\MkSQL\Repository\Attributes\ColumnType; | ||
use Zrnik\MkSQL\Repository\Attributes\PrimaryKey; | ||
use Zrnik\MkSQL\Repository\Attributes\TableName; | ||
use Zrnik\MkSQL\Repository\BaseEntity; | ||
|
||
#[TableName('hook_test_AfterSaveHookEntity')] | ||
class AfterSaveHookEntity extends BaseEntity | ||
{ | ||
#[PrimaryKey] | ||
public ?int $id = null; | ||
|
||
#[ColumnType('varchar(100)')] | ||
public string $afterSaveException = 'Hello World'; | ||
|
||
/** | ||
* @throws EntityWithHookException | ||
* @noinspection PhpMissingParentCallCommonInspection | ||
*/ | ||
public function afterSave(): void | ||
{ | ||
throw new EntityWithHookException(EntityHookExceptionType::AFTER_SAVE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\Mock\EntitiesWithHooks; | ||
|
||
use Zrnik\MkSQL\Repository\Attributes\PrimaryKey; | ||
use Zrnik\MkSQL\Repository\Attributes\TableName; | ||
use Zrnik\MkSQL\Repository\BaseEntity; | ||
|
||
#[TableName('hook_test_BeforeSaveHookEntity')] | ||
class BeforeSaveHookEntity extends BaseEntity | ||
{ | ||
#[PrimaryKey] | ||
public ?int $id = null; | ||
|
||
/** | ||
* @throws EntityWithHookException | ||
* @noinspection PhpMissingParentCallCommonInspection | ||
*/ | ||
public function beforeSave(): void | ||
{ | ||
throw new EntityWithHookException(EntityHookExceptionType::BEFORE_SAVE); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\Mock\EntitiesWithHooks; | ||
|
||
use Zrnik\Base\Enum; | ||
|
||
class EntityHookExceptionType extends Enum | ||
{ | ||
public const BEFORE_SAVE = 0; | ||
public const AFTER_SAVE = 1; | ||
|
||
public const AFTER_RETRIEVE = 10; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\Mock\EntitiesWithHooks; | ||
|
||
use Zrnik\MkSQL\Updater; | ||
use Zrnik\MkSQL\Utilities\Installable; | ||
|
||
class EntityHookRepository extends Installable | ||
{ | ||
protected function install(Updater $updater): void | ||
{ | ||
$updater->use(AfterRetrieveHookEntity::class); | ||
$updater->use(AfterSaveHookEntity::class); | ||
$updater->use(BeforeSaveHookEntity::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Tests\Mock\EntitiesWithHooks; | ||
|
||
use Exception; | ||
|
||
class EntityWithHookException extends Exception | ||
{ | ||
public int $hookExceptionType; | ||
|
||
public function __construct(int $hookExceptionType) | ||
{ | ||
$this->hookExceptionType = $hookExceptionType; | ||
|
||
parent::__construct( | ||
sprintf( | ||
'Hook exception "%s" thrown!', | ||
EntityHookExceptionType::getName($hookExceptionType) | ||
) | ||
); | ||
} | ||
} |