Skip to content

Releases: aternosorg/php-model

v3.2.5

15 Jul 13:08
882e03c
Compare
Choose a tag to compare

What's Changed

Full Changelog: v3.2.4...v3.2.5

v3.2.4

15 Jan 13:24
283f572
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v3.2.3...v3.2.4

v3.2.3

30 Jun 15:46
97adb4e
Compare
Choose a tag to compare
fix warning

v3.2.2

30 Jun 12:54
ea88b15
Compare
Choose a tag to compare
clear model registry when clearing test entries, add functions to tem…

v3.2.1

30 Jun 12:34
191697a
Compare
Choose a tag to compare

What's Changed

Full Changelog: v3.2.0...v3.2.1

v3.2.0

29 Jun 16:46
5b61f0b
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v3.1.0...v3.2.0

v3.1.0

22 Jun 12:21
5683082
Compare
Choose a tag to compare
fix limit for update and delete queries, added affected rows to query…

3.0.0

15 Mar 16:19
202a10a
Compare
Choose a tag to compare

Main breaking changes

ModelInterface ID type

The ModelInterface ID is now typed as mixed. Any model extending GenericModel
have to change the type of the $id property to mixed:

class MyModel extends GenericModel
{
    public $id;
}

has to be changed to

class MyModel extends GenericModel
{
    public mixed $id;
}

QueryResult getter

The magic getter function of QueryResult was removed. They have to be accessed using the correct
array key (usually [0]).

$queryResult = MyModel::select(["field" => "value"]);
$value = $queryResult->field;

has to be changed to

$queryResult = MyModel::select(["field" => "value"]);
$value = $queryResult[0]?->field;

Dynamic properties

Dynamic properties are deprecated since PHP 8.2. Unknown fields are now stored in BaseModel->$additionalFields
and have to be accessed using the new ModelInterface->getField(string $key): mixed function.

$queryResult = MyModel::select(fields: [(new \Aternos\Model\Query\SelectField("field"))->setAlias("alias")]);
$value = $queryResult[0]?->alias;

has to be changed to

$queryResult = MyModel::select(fields: [(new \Aternos\Model\Query\SelectField("field"))->setAlias("alias")]);
$value = $queryResult[0]?->getField("alias");

Changed

  • Potentially breaking type changes/additions:
    • The ModelInterface ID is now typed as mixed. This also affects the
      ModelInterface->getId(): mixed and ModelInterface->setId(mixed $id): static methods.
    • ModelInterface->setId(mixed $id): static now returns static instead of void.
    • ModelInterface::get(): ?static now returns null if the model is not found
      instead of false.
    • ModelInterface::getIdField() and ModelInterface::getCacheTime() are now static.
    • ModelCollection offset functions (from ArrayAccess) now have mixed types for all
      arguments to follow the ArrayAccess interface.
    • ModelRegistry->get(): ?ModelInterface now returns null if the model is not found
      instead of false.
    • BaseModel->__construct(mixed $id) now has the typed argument mixed $id.
    • GenericModel::select() and GenericModel::update() now have fully typed arguments.
    • GenericModel->set() now has the return type QueryResult.
    • All Query classes now have proper typing for their arguments and return types.
    • GettableInterface->get(string $modelClass, mixed $id, ?ModelInterface $model = null): ?ModelInterface only optionally
      applies data to a given model, usually it creates a new model using ModelInterface::getModelFromData(array $rawData): ?static
      It also returns null if the model is not found instead of false.
  • ModelRegistry->get(string $className, string $id): ?ModelInterface now takes the class name
    as the first argument instead of the model name. This function is also generic and type hints
    the return type from the first argument.
  • Fields that aren't defined in the model are no longer set as dynamic properties. They
    have to be retrieved using the new ModelInterface->getField(string $key): mixed function.

Added

  • ModelCollection and its children now have generic type hinting in phpdoc allowing for type
    hinting the model type in the collection.
  • GenericModel now has the ability to define different GenericModel::$variants which are child
    classes of a basic model to separate different subtypes of a model. Each variant can different
    GenericModel::$filters which are key value pairs that identify the type. Direct calls to get and
    query functions will automatically filter the results to the correct variant. Calls to the shared
    parent model will return all variants but of the correct subtype.
  • Added CountField and GenericModel::count() for easier count queries.
  • Added SumField and AverageField.
  • Added GenericModel::reload(): static to reload the model from the database.

Removed

  • Removed SimpleModel.
  • Removed magic getter from QueryResult.

v1.2.0

24 Mar 12:42
8a45ca0
Compare
Choose a tag to compare

This release changes the minimum required PHP version to PHP 8.0.

What's Changed

  • Added more return types for PHP 8.1 compatibility.
  • Update license year and rename Aternos UG to Aternos GmbH by @pavog in #1

New Contributors

  • @pavog made their first contribution in #1

Full Changelog: v1.1.4...v1.2.0

v1.1.4

10 Feb 10:17
a474d7b
Compare
Choose a tag to compare

added more types for php 8.1 compatibility