Skip to content

Commit

Permalink
implement the interface ArrayableInterface for BaseActiveRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
niqingyang committed Dec 11, 2023
1 parent e299dfa commit 1f86104
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/ActiveRecordInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
namespace Yiisoft\ActiveRecord;

use Throwable;
use Yiisoft\Arrays\ArrayableInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Exception\StaleObjectException;

interface ActiveRecordInterface extends ArrayableInterface
interface ActiveRecordInterface
{
/**
* Returns the list of all attribute names of the model.
Expand Down Expand Up @@ -86,6 +85,14 @@ public function deleteAll(array $condition = []): int;
*/
public function equals(self $record): bool;

/**
* @return array The default implementation returns the names of the columns whose values have been populated into
* this record.
*
* @psalm-return array<string, string|Closure>

Check failure on line 92 in src/ActiveRecordInterface.php

View workflow job for this annotation

GitHub Actions / PHP 8-ubuntu-latest

UndefinedDocblockClass: Docblock-defined class, interface or enum named Yiisoft\ActiveRecord\Closure does not exist

Check failure on line 92 in src/ActiveRecordInterface.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

UndefinedDocblockClass: Docblock-defined class, interface or enum named Yiisoft\ActiveRecord\Closure does not exist
*/
public function fields(): array;

/**
* Filters array condition before it's assigned to a Query filter.
*
Expand Down Expand Up @@ -491,4 +498,19 @@ public function getOldAttributes(): array;
* @throws InvalidConfigException
*/
public function populateRecord(array|object $row): void;

/**
* Serializes the active record into its array implementation with attribute name as a key, and it values as value.
*
* @param array $fields the fields that the output array should contain. Fields not specified
* in {@see fields()} will be ignored. If this parameter is empty, all fields as specified
* in {@see fields()} will be returned.
* @param array $expand the additional fields that the output array should contain.
* Fields not specified in {@see extraFields()} will be ignored. If this parameter is empty, no extra fields
* will be returned.
* @param bool $recursive Whether to recursively return array representation of embedded objects.
*
* @return array The array representation of the object.
*/
public function toArray(array $fields = [], array $expand = [], bool $recursive = true): array;
}
3 changes: 2 additions & 1 deletion src/BaseActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use IteratorAggregate;
use ReflectionException;
use Throwable;
use Yiisoft\Arrays\ArrayableInterface;
use Yiisoft\Arrays\ArrayableTrait;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Exception\Exception;
Expand Down Expand Up @@ -41,7 +42,7 @@
* @template-implements ArrayAccess<int, mixed>
* @template-implements IteratorAggregate<int>
*/
abstract class BaseActiveRecord implements ActiveRecordInterface, IteratorAggregate, ArrayAccess
abstract class BaseActiveRecord implements ActiveRecordInterface, IteratorAggregate, ArrayAccess, ArrayableInterface
{
use ArrayableTrait;
use BaseActiveRecordTrait;
Expand Down

0 comments on commit 1f86104

Please sign in to comment.