-
-
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
2 changed files
with
38 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,36 @@ | |
use Cycle\ORM\RepositoryInterface; | ||
use Cycle\ORM\Transaction\StateInterface; | ||
|
||
/** | ||
* A base class for entities that are managed by the ORM. | ||
* Adds a set of ActiveRecord methods to the extending entity class. | ||
*/ | ||
abstract class ActiveRecord | ||
{ | ||
/** | ||
* Creates a new entity instance with the given data. | ||
* It is preferable to use this method instead of the constructor because | ||
* it uses ORM services to create the entity. | ||
* | ||
* Equals to calling {@see ORMInterface::make()}. | ||
* | ||
* @param array<non-empty-string, mixed> $data An associative array where keys are property names | ||
* and values are property values. | ||
* | ||
* Example: | ||
* | ||
* ```php | ||
* $user = User::make([ | ||
* 'name' => 'John Doe', | ||
* 'email' => '[email protected]', | ||
* ]); | ||
* ``` | ||
*/ | ||
public static function make(array $data): static | ||
{ | ||
return self::getOrm()->make(static::class, $data); | ||
} | ||
|
||
/** | ||
* Finds a single record based on the given primary key. | ||
*/ | ||
|
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