Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from mrakolice/schema-defaults
Add possibility to change default schema classes
- Loading branch information
Showing
6 changed files
with
408 additions
and
49 deletions.
There are no files selected for viewing
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,74 @@ | ||
<?php | ||
|
||
namespace Cycle\ORM\Select; | ||
|
||
use Cycle\ORM\ORMInterface; | ||
use Cycle\ORM\Select; | ||
use Cycle\ORM\Transaction; | ||
|
||
class PersistRepository extends Repository | ||
{ | ||
/** @var Transaction */ | ||
private $transaction; | ||
|
||
/** | ||
* @param Select $select | ||
* @param ORMInterface $orm | ||
*/ | ||
public function __construct( | ||
Select $select, | ||
ORMInterface $orm | ||
) { | ||
parent::__construct($select); | ||
$this->transaction = new Transaction($orm); | ||
} | ||
|
||
/** | ||
* @param mixed $entity | ||
* @param bool $cascade | ||
* | ||
* @throws \Throwable | ||
*/ | ||
public function save( | ||
$entity, | ||
bool $cascade = true | ||
): void { | ||
$this->transaction->persist( | ||
$entity, | ||
$cascade ? Transaction::MODE_CASCADE : Transaction::MODE_ENTITY_ONLY | ||
); | ||
|
||
$this->transaction->run(); // transaction is clean after run | ||
} | ||
|
||
/** | ||
* @param mixed $entity | ||
* @param bool $cascade | ||
* | ||
* @throws \Throwable | ||
*/ | ||
public function delete( | ||
$entity, | ||
bool $cascade = true | ||
): void { | ||
$this->transaction->persist( | ||
$entity, | ||
$cascade ? Transaction::MODE_CASCADE : Transaction::MODE_ENTITY_ONLY | ||
); | ||
|
||
$this->transaction->run(); // transaction is clean after run | ||
} | ||
|
||
/** | ||
* @param $id | ||
* @param bool $cascade | ||
* | ||
* @throws \Throwable | ||
*/ | ||
public function deleteByPK( | ||
$id, | ||
bool $cascade = true | ||
): void { | ||
$this->delete($this->findByPK($id), $cascade); | ||
} | ||
} |
Oops, something went wrong.