All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.
- The new
ListenerException
class can be thrown from event listeners as a shortcut to stop events. - A
deleted
property has been added to soft deleted models. - The
Query::one()
method finds exactly one model or throws an exception. - The
Query::oneOrNull()
method finds exactly one model or returns null. - Capture the options of the failing validation rule for more accurate error messages.
- Added
Iterator::toArray()
as a shortcut toiterator_to_array
Query::where()
now accepts models as conditions- Doctrine 3 compatibility if using the DBAL driver
- Added
Model::deleteOrFail()
method. - The model ID property names can be obtained with
Definition::getIds()
- Use PHPDoc generics when possible
- Added
enum
model property type. - Added
date
anddatetime
property types that useDateTimeInterface
objects.
- Moved adding event listeners and dispatching events to
EventManager
- Queries against models that support soft deletes now return all models by default. Use
::withoutDeleted()
to exclude deleted models from a query. - Soft delete logic has been moved to the
SoftDelete
trait - Use @mixin instead of @method for query operations on model
Query::first()
now returns an array of results when the limit is 1- Added return typehint to
AclModel::hasPermission()
- PHP 8.1 is required at minimum
- Changed all
BadMethodCallException
toModelException
Query::set()
andQuery::delete()
now throw an exception if any operation fails- Queries attempt to detect and prevent duplicate joins
- Model ID properties are now provided by
Model::getIDProperties()
instead ofModel::$ids
.Model::getIDProperties()
is now a protected method instead of public. - Model properties are now provided by
Model::getProperties()
instead ofModel::$properties
- Any
autoDefinition
methods should return an array of properties that will be added to the list of model properties - The constructor arguments to
Property
are now typed and promoted to readonly constructor properties. An array of properties is no longer accepted. - Property definitions must return
Property
objects instead of arrays - Renamed the
date
type todate_unix
- Renamed
getMassAssignmentWhitelist()
andgetMassAssignmentBlacklist()
- Rollback database transaction after uncaught exception during model persistence.
- The return types of average, min, max, and sum in the database drivers was incorrect.
- The model is unmarked as persisted if the post-create listener fails.
- The iterator no longer returns null values in a foreach loop.
- Model queries with an IN condition and no operator did not generate the correct SQL.
Model::getDispatcher()
was removed and replaced with theEventManager
class.Model::$hidden
,Model::$appended
,Model::$permitted
, andModel::$protected
were removed.
- You can now supply your own translation implementation with
TranslatorInterface
. A simple translation implementation is provided with Pulsar. - The
Errors::setTranslator()
method can set the global translation implementation. - Models now have a
buildDefinition()
method that can be overridden to dynamically customize the model properties. - Added
Model::dirty()
to check for unsaved values, and detect changes to those values. - Added
Type::*
,Property::*
, andRelationship::*
constants to replace removedModel
constants. - New method
Model::hasId()
will indicate when a model has a complete identifier. - Model definitions have new shortcuts to define relationships:
belongs_to
,belongs_to_many
,has_many
,has_one
, andmorphs_to
. - Added
encrypt
validation rule to encrypt values prior to saving to database using defuse/php-encryption. - Added
encrypt
setting to model definitions that when enabled will encrypt the property value in the database. - Added polymorphic relationship type.
- Saved values are no longer validated by
Model::valid()
. Only unsaved values will be validated. - Callable validation rules can now set their own validation error message.
- Added
Model::beforePersist()
andModel::afterPersist()
shortcut to install lifecycle event listeners for all create, update, and delete. - Added
Model::getMassAssignmentWhitelist()
andModel::getMassAssignmentBlacklist()
that can be overriden to define mass assignment rules. - Added
in_array
model definition setting to indicate whether a property is included in the array representation.
- Make model internal properties private when possible.
- The package no longer depends on
infuse/libs
. - Renamed
Property
class toType
. - A new
Definition
class contains all the properties that belong to a method. Retrieving the model properties withModel::definition()
will return this object instead of an array. - A new
Property
class encapsulates the definition of a model property. The model property methods will return this object instead of an array. - Moved
Model::cast()
toType::cast()
- Marked classes as final when appropriate.
- The model constructor no longer has an
$id
argument. Instead you can usenew Model(['id' => 1234])
. - Changed the structure of the
validate
property setting to be an array with named options. - The unique constraint is now a validation rule specified as:
['validate' => ['unique', 'column' => 'email']]
. - Callable validation rules must now be specified as:
['validate' => ['callable', 'fn' => ...]]
. - The error stack represents error messages as objects instead of arrays.
- Lifecycle events are now represented as a different class for each event type.
- Automatic timestamps are now installed with the
AutoTimestamps
trait. - Soft delete is now enabled with the
SoftDelete
trait. - Deprecated
Model::$hidden
,Model::$appended
,Model::$permitted
, andModel::$protected
.\ - All class properties, method arguments, and method return values have type hints.
- Use a strict equality check when casting an empty string to null on a nullable property. Previously this would check for a falsey value.
- Ensure
Model::definition()
is always called in static context
- Removed
Errors::setLocale
,Errors::getLocale()
, andErrors::setGlobalLocale()
. It is now required to useErrors::setTranslator()
. - Removed the
toArrayHook()
call. It is recommended to overridetoArray()
if it is necessary to modify its output. - Removed
Model::TYPE_*
,Model
mutability, andModel::RELATIONSHIP_*
constants. - Removed
Model::getProperties()
,::hasProperty()
, and::getProperty()
. - Removed the
password_php
validation rule in favor ofpassword
. - It is no longer possible to supply a locale when grabbing error messages.
- Removed the
ModelEvent
class.
- Added a DBAL driver.
- Model operations will now be wrapped in database transactions by overriding the
Model::usesTransactions()
method.
- Added argument and return type hinting to most methods.
- Ensure that the array property type always returns an array
- Removed the
DriverException::getException()
method in favor ofgetPrevious()
. - Removed the number property type. Use integer or float instead.
- Removed
exists()
on model class. - Removed
title
setting on model properties. - Removed
ACLModel::setRequester()
andACLModel::getRequester()
- Removed
Errors::errors()
,Errors::messages()
, andErrors::push()
- Removed
Query::totalRecords()
- Removed the
preSetHook()
method call during themodel.updating
event. If you need to use this functionality install the below event listener in your model.use Pulsar\Event\AbstractEvent; self::updating(function (AbstractEvent $modelEvent) { $model = $modelEvent->getModel(); if (!$model->preSetHook($model->_unsaved)) { $modelEvent->stopPropagation(); } }, -512);
- Querying a belongs-to relationship with eager loading could return incorrect results.
- Updated Symfony dependency to version 4.3+
- PHP 7.1 is the minimum supported version
- There is a
relation_type
setting on model properties that defaults tobelongs_to
. - Added a
local_key
setting on model properties for overriding the default local key on relationships. - Added a
foreign_key
setting on model properties for overriding the default foreign key on relationships. - Added a
pivot_tablename
setting on model properties for overriding the default pivot table name on belongs-to-many relationships. - Added a Collection class to represent a collection of models and provide functionality around managing that collection.
- Implemented eager loading for has-one and has-many relationships.
- The
ACLModelRequester
class now holds the current requester and supports callables for lazy-loading.
- Reduce a loadModel call by caching the values after a save.
- Use Relation classes in
relation()
instead of::find()
. - Deprecated
ACLModel::setRequester()
andACLModel::getRequester()
- Catch
PDOException
ingetConnection()
and rethrow asDriverException
database driver. - The time zone validator was rejecting many valid time zones.
- Can set global locale instance **used by error instances with
Errors::setGlobalLocale()
.
- Relax
icanboogie/inflector
version dependency.
- Fetching non-existent or dynamic properties no longer calls refresh().
- De-duplicate eager loaded relationships set using
with()
.
- Removed global error stack support and Infuse error stack service.
- No longer support
db
service with Infuse. Now you must use thedatabase
service set to connection manager. - Remove
Model::getApp()
and no longer inject a global Infuse container into models.
- Support Symfony 4.
- Require PHP 7.
- Update infuse/libs to v1.
- Removed
password
validator.
- Add more detail to saveOrFail() exception messages.
- Added
password_php
validator that uses PHP's password hashing. - Property titles are now looked up from
pulsar.properties.*
locale phrases.
- Deprecated
password
validator. - Validator configuration has been moved to
models.validator
namespace.
- Validating values with multiple validation rules short-circuits on the first failed rule.
- ACLModel was incorrectly caching permissions.
- Added
valid()
method to model.
- Add join conditions to aggregate queries.
- Prefix columns used in aggregate queries.
- Clear previous validation errors before each save.
- Soft deletes when model has
::$softDelete
property. - Added
sum()
,average()
,max()
, andmin()
methods to queries.
- Refactored
ErrorStack
class intoErrors
class. - Refactored
Validate
class intoValidator
class. - Deprecated several error methods.
- Improved validation error messaging.
- Renamed
totalRecords
on driver interface tocount()
. - Model properties no longer casted to string type by default.
- Giving an invalid ID to
find()
no longer triggers a PHP error. - Ensure model ID is properly type cast.
- Added
set()
method to queries for batch updates. - Added
delete()
method to queries for batch deletes. - Added many helper methods to relationships, including
save()
,create()
,sync()
,attach()
, anddetach()
. - Moved
getTablename()
out of database driver and into model class. - Added
saveOrFail()
method to models. - Added support for multiple database connections.
- Added
getConnection()
method to models for specifying the connection that a model should use.
- Models are always marked as persisted immediately after saving.
- Model queries now have a
count()
method to return the total number of records. - Added
setRelation()
method to be used withrelation()
. - Added
with()
for eager loading relationships.
- Deprecated
Model::totalRecords()
. - When the iterator gets a model count it reuses the same query instead of creating a new one.
- The deprecated
relation()
method now performs a lookup on the data layer and can return null values. Model::find()
now usesqueryModels()
on the data driver instead of usingloadModel()
.- Models can now maintain their own error stack instances.
- Deprecate storing DI container on models.
- Database driver no longer requires a DI container.
ErrorStack
no longer requires a DI container or locale instance.
- Models no longer have
$this->app
property.
DriverException
represents errors that occur in the data layer.- Added model adapter service for Infuse Framework.
- Added error stack service for Infuse Framework.
- Added
Model::saved()
andModel::saving()
shortcuts for listening to any write operation. - Added integer and float property types.
- Added
Model::find()
andModel::findOrFail()
for loading models from the data layer. - Added
persisted()
method to model class. - Added optional mass assignment protection via
Model::$protected
andModel::$permitted
.
- All model-related exceptions inherit from
ModelException
. - Support Symfony 3.
- Use version 0.6 of
infuse/libs
. - Deprecated
relation()
on model class. - Deprecated
exists()
on model class. - Deprecated
toArrayHook()
on model class. - Deprecated
preSetHook()
on model class. - Deprecated number property type.
- Deprecated
Validate::is()
. - Imported error stack library from
infuse/libs
. - Calling
delete()
no longer clears the local values cache. - Models with auto-timestamps now compute
created_at
andupdated_at
instead of relying on database triggers. - Use PSR-6 in
Cacheable
trait.
- Removed
toArrayDeprecated()
on model class. - Removed
load()
on model class. - Removed deprecated hooks for create and delete operations.
- Throw exception when calling
create()
,set()
, ordelete()
inappropriately. - Mass assigned values in
set()
are now available in themodel.updating
event. - Models returned by
toArray()
will be converted to arrays.
- Initial release! Project imported from
infuse/libs
.