Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Model often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Model, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | abstract class Model implements \ArrayAccess |
||
| 30 | { |
||
| 31 | const IMMUTABLE = 0; |
||
| 32 | const MUTABLE_CREATE_ONLY = 1; |
||
| 33 | const MUTABLE = 2; |
||
| 34 | |||
| 35 | const TYPE_STRING = 'string'; |
||
| 36 | const TYPE_NUMBER = 'number'; // DEPRECATED |
||
| 37 | const TYPE_INTEGER = 'integer'; |
||
| 38 | const TYPE_FLOAT = 'float'; |
||
| 39 | const TYPE_BOOLEAN = 'boolean'; |
||
| 40 | const TYPE_DATE = 'date'; |
||
| 41 | const TYPE_OBJECT = 'object'; |
||
| 42 | const TYPE_ARRAY = 'array'; |
||
| 43 | |||
| 44 | const ERROR_REQUIRED_FIELD_MISSING = 'required_field_missing'; |
||
| 45 | const ERROR_VALIDATION_FAILED = 'validation_failed'; |
||
| 46 | const ERROR_NOT_UNIQUE = 'not_unique'; |
||
| 47 | |||
| 48 | const DEFAULT_ID_PROPERTY = 'id'; |
||
| 49 | |||
| 50 | ///////////////////////////// |
||
| 51 | // Model visible variables |
||
| 52 | ///////////////////////////// |
||
| 53 | |||
| 54 | /** |
||
| 55 | * List of model ID property names. |
||
| 56 | * |
||
| 57 | * @var array |
||
| 58 | */ |
||
| 59 | protected static $ids = [self::DEFAULT_ID_PROPERTY]; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Property definitions expressed as a key-value map with |
||
| 63 | * property names as the keys. |
||
| 64 | * i.e. ['enabled' => ['type' => Model::TYPE_BOOLEAN]]. |
||
| 65 | * |
||
| 66 | * @var array |
||
| 67 | */ |
||
| 68 | protected static $properties = []; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var Container |
||
| 72 | */ |
||
| 73 | protected static $injectedApp; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var array |
||
| 77 | */ |
||
| 78 | protected static $dispatchers; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var number|string|bool |
||
| 82 | */ |
||
| 83 | protected $_id; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var Container |
||
| 87 | */ |
||
| 88 | protected $app; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var array |
||
| 92 | */ |
||
| 93 | protected $_values = []; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var array |
||
| 97 | */ |
||
| 98 | protected $_unsaved = []; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var bool |
||
| 102 | */ |
||
| 103 | protected $_persisted = false; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @var array |
||
| 107 | */ |
||
| 108 | protected $_relationships = []; |
||
| 109 | |||
| 110 | ///////////////////////////// |
||
| 111 | // Base model variables |
||
| 112 | ///////////////////////////// |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var array |
||
| 116 | */ |
||
| 117 | private static $propertyDefinitionBase = [ |
||
| 118 | 'type' => self::TYPE_STRING, |
||
| 119 | 'mutable' => self::MUTABLE, |
||
| 120 | 'null' => false, |
||
| 121 | 'unique' => false, |
||
| 122 | 'required' => false, |
||
| 123 | ]; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @var array |
||
| 127 | */ |
||
| 128 | private static $defaultIDProperty = [ |
||
| 129 | 'type' => self::TYPE_INTEGER, |
||
| 130 | 'mutable' => self::IMMUTABLE, |
||
| 131 | ]; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @var array |
||
| 135 | */ |
||
| 136 | private static $timestampProperties = [ |
||
| 137 | 'created_at' => [ |
||
| 138 | 'type' => self::TYPE_DATE, |
||
| 139 | 'validate' => 'timestamp|db_timestamp', |
||
| 140 | ], |
||
| 141 | 'updated_at' => [ |
||
| 142 | 'type' => self::TYPE_DATE, |
||
| 143 | 'validate' => 'timestamp|db_timestamp', |
||
| 144 | ], |
||
| 145 | ]; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @var array |
||
| 149 | */ |
||
| 150 | private static $initialized = []; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @var DriverInterface |
||
| 154 | */ |
||
| 155 | private static $driver; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @var array |
||
| 159 | */ |
||
| 160 | private static $accessors = []; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @var array |
||
| 164 | */ |
||
| 165 | private static $mutators = []; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @var bool |
||
| 169 | */ |
||
| 170 | private $_ignoreUnsaved; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Creates a new model object. |
||
| 174 | * |
||
| 175 | * @param array|string|Model|false $id ordered array of ids or comma-separated id string |
||
| 176 | * @param array $values optional key-value map to pre-seed model |
||
| 177 | */ |
||
| 178 | public function __construct($id = false, array $values = []) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Performs initialization on this model. |
||
| 210 | */ |
||
| 211 | private function init() |
||
| 220 | |||
| 221 | /** |
||
| 222 | * The initialize() method is called once per model. It's used |
||
| 223 | * to perform any one-off tasks before the model gets |
||
| 224 | * constructed. This is a great place to add any model |
||
| 225 | * properties. When extending this method be sure to call |
||
| 226 | * parent::initialize() as some important stuff happens here. |
||
| 227 | * If extending this method to add properties then you should |
||
| 228 | * call parent::initialize() after adding any properties. |
||
| 229 | */ |
||
| 230 | protected function initialize() |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Installs the `created_at` and `updated_at` properties. |
||
| 258 | */ |
||
| 259 | private function installAutoTimestamps() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Injects a DI container. |
||
| 276 | * |
||
| 277 | * @param Container $app |
||
| 278 | */ |
||
| 279 | public static function inject(Container $app) |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Gets the DI container used for this model. |
||
| 286 | * |
||
| 287 | * @return Container |
||
| 288 | */ |
||
| 289 | public function getApp() |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Sets the driver for all models. |
||
| 296 | * |
||
| 297 | * @param DriverInterface $driver |
||
| 298 | */ |
||
| 299 | public static function setDriver(DriverInterface $driver) |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Gets the driver for all models. |
||
| 306 | * |
||
| 307 | * @return DriverInterface |
||
| 308 | * |
||
| 309 | * @throws DriverMissingException when a driver has not been set yet |
||
| 310 | */ |
||
| 311 | public static function getDriver() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Clears the driver for all models. |
||
| 322 | */ |
||
| 323 | public static function clearDriver() |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Gets the name of the model, i.e. User. |
||
| 330 | * |
||
| 331 | * @return string |
||
| 332 | */ |
||
| 333 | public static function modelName() |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Gets the model ID. |
||
| 343 | * |
||
| 344 | * @return string|number|false ID |
||
| 345 | */ |
||
| 346 | public function id() |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Gets a key-value map of the model ID. |
||
| 353 | * |
||
| 354 | * @return array ID map |
||
| 355 | */ |
||
| 356 | public function ids() |
||
| 374 | |||
| 375 | ///////////////////////////// |
||
| 376 | // Magic Methods |
||
| 377 | ///////////////////////////// |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Converts the model into a string. |
||
| 381 | * |
||
| 382 | * @return string |
||
| 383 | */ |
||
| 384 | public function __toString() |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Shortcut to a get() call for a given property. |
||
| 391 | * |
||
| 392 | * @param string $name |
||
| 393 | * |
||
| 394 | * @return mixed |
||
| 395 | */ |
||
| 396 | public function __get($name) |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Sets an unsaved value. |
||
| 405 | * |
||
| 406 | * @param string $name |
||
| 407 | * @param mixed $value |
||
| 408 | */ |
||
| 409 | public function __set($name, $value) |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Checks if an unsaved value or property exists by this name. |
||
| 427 | * |
||
| 428 | * @param string $name |
||
| 429 | * |
||
| 430 | * @return bool |
||
| 431 | */ |
||
| 432 | public function __isset($name) |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Unsets an unsaved value. |
||
| 439 | * |
||
| 440 | * @param string $name |
||
| 441 | */ |
||
| 442 | public function __unset($name) |
||
| 453 | |||
| 454 | ///////////////////////////// |
||
| 455 | // ArrayAccess Interface |
||
| 456 | ///////////////////////////// |
||
| 457 | |||
| 458 | public function offsetExists($offset) |
||
| 462 | |||
| 463 | public function offsetGet($offset) |
||
| 467 | |||
| 468 | public function offsetSet($offset, $value) |
||
| 472 | |||
| 473 | public function offsetUnset($offset) |
||
| 477 | |||
| 478 | public static function __callStatic($name, $parameters) |
||
| 485 | |||
| 486 | ///////////////////////////// |
||
| 487 | // Property Definitions |
||
| 488 | ///////////////////////////// |
||
| 489 | |||
| 490 | /** |
||
| 491 | * Gets all the property definitions for the model. |
||
| 492 | * |
||
| 493 | * @return array key-value map of properties |
||
| 494 | */ |
||
| 495 | public static function getProperties() |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Gets a property defition for the model. |
||
| 502 | * |
||
| 503 | * @param string $property property to lookup |
||
| 504 | * |
||
| 505 | * @return array|null property |
||
| 506 | */ |
||
| 507 | public static function getProperty($property) |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Gets the names of the model ID properties. |
||
| 514 | * |
||
| 515 | * @return array |
||
| 516 | */ |
||
| 517 | public static function getIDProperties() |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Checks if the model has a property. |
||
| 524 | * |
||
| 525 | * @param string $property property |
||
| 526 | * |
||
| 527 | * @return bool has property |
||
| 528 | */ |
||
| 529 | public static function hasProperty($property) |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Gets the mutator method name for a given proeprty name. |
||
| 536 | * Looks for methods in the form of `setPropertyValue`. |
||
| 537 | * i.e. the mutator for `last_name` would be `setLastNameValue`. |
||
| 538 | * |
||
| 539 | * @param string $property property |
||
| 540 | * |
||
| 541 | * @return string|false method name if it exists |
||
| 542 | */ |
||
| 543 | View Code Duplication | public static function getMutator($property) |
|
| 561 | |||
| 562 | /** |
||
| 563 | * Gets the accessor method name for a given proeprty name. |
||
| 564 | * Looks for methods in the form of `getPropertyValue`. |
||
| 565 | * i.e. the accessor for `last_name` would be `getLastNameValue`. |
||
| 566 | * |
||
| 567 | * @param string $property property |
||
| 568 | * |
||
| 569 | * @return string|false method name if it exists |
||
| 570 | */ |
||
| 571 | View Code Duplication | public static function getAccessor($property) |
|
| 589 | |||
| 590 | ///////////////////////////// |
||
| 591 | // CRUD Operations |
||
| 592 | ///////////////////////////// |
||
| 593 | |||
| 594 | /** |
||
| 595 | * Saves the model. |
||
| 596 | * |
||
| 597 | * @return bool true when the operation was successful |
||
| 598 | */ |
||
| 599 | public function save() |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Creates a new model. |
||
| 610 | * |
||
| 611 | * @param array $data optional key-value properties to set |
||
| 612 | * |
||
| 613 | * @return bool true when the operation was successful |
||
| 614 | * |
||
| 615 | * @throws BadMethodCallException when called on an existing model |
||
| 616 | */ |
||
| 617 | public function create(array $data = []) |
||
| 702 | |||
| 703 | /** |
||
| 704 | * Ignores unsaved values when fetching the next value. |
||
| 705 | * |
||
| 706 | * @return self |
||
| 707 | */ |
||
| 708 | public function ignoreUnsaved() |
||
| 714 | |||
| 715 | /** |
||
| 716 | * Fetches property values from the model. |
||
| 717 | * |
||
| 718 | * This method looks up values in this order: |
||
| 719 | * IDs, local cache, unsaved values, storage layer, defaults |
||
| 720 | * |
||
| 721 | * @param array $properties list of property names to fetch values of |
||
| 722 | * |
||
| 723 | * @return array |
||
| 724 | */ |
||
| 725 | public function get(array $properties) |
||
| 770 | |||
| 771 | /** |
||
| 772 | * Gets the ID for a newly created model. |
||
| 773 | * |
||
| 774 | * @return string |
||
| 775 | */ |
||
| 776 | protected function getNewID() |
||
| 793 | |||
| 794 | /** |
||
| 795 | * Sets a collection values on the model from an untrusted input. |
||
| 796 | * |
||
| 797 | * @param array $values |
||
| 798 | * |
||
| 799 | * @return self |
||
| 800 | */ |
||
| 801 | public function setValues($values) |
||
| 810 | |||
| 811 | /** |
||
| 812 | * Converts the model to an array. |
||
| 813 | * |
||
| 814 | * @return array |
||
| 815 | */ |
||
| 816 | public function toArray() |
||
| 839 | |||
| 840 | /** |
||
| 841 | * Updates the model. |
||
| 842 | * |
||
| 843 | * @param array $data optional key-value properties to set |
||
| 844 | * |
||
| 845 | * @return bool true when the operation was successful |
||
| 846 | * |
||
| 847 | * @throws BadMethodCallException when not called on an existing model |
||
| 848 | */ |
||
| 849 | public function set(array $data = []) |
||
| 913 | |||
| 914 | /** |
||
| 915 | * Delete the model. |
||
| 916 | * |
||
| 917 | * @return bool true when the operation was successful |
||
| 918 | */ |
||
| 919 | public function delete() |
||
| 943 | |||
| 944 | ///////////////////////////// |
||
| 945 | // Queries |
||
| 946 | ///////////////////////////// |
||
| 947 | |||
| 948 | /** |
||
| 949 | * Generates a new query instance. |
||
| 950 | * |
||
| 951 | * @return Query |
||
| 952 | */ |
||
| 953 | public static function query() |
||
| 962 | |||
| 963 | /** |
||
| 964 | * Finds a single instance of a model given it's ID. |
||
| 965 | * |
||
| 966 | * @param mixed $id |
||
| 967 | * |
||
| 968 | * @return Model|false |
||
| 969 | */ |
||
| 970 | public static function find($id) |
||
| 980 | |||
| 981 | /** |
||
| 982 | * Finds a single instance of a model given it's ID or throws an exception. |
||
| 983 | * |
||
| 984 | * @param mixed $id |
||
| 985 | * |
||
| 986 | * @return Model |
||
| 987 | * |
||
| 988 | * @throws ModelNotFoundException when a model could not be found |
||
| 989 | */ |
||
| 990 | public static function findOrFail($id) |
||
| 999 | |||
| 1000 | /** |
||
| 1001 | * Gets the total number of records matching an optional criteria. |
||
| 1002 | * |
||
| 1003 | * @param array $where criteria |
||
| 1004 | * |
||
| 1005 | * @return int |
||
| 1006 | */ |
||
| 1007 | public static function totalRecords(array $where = []) |
||
| 1014 | |||
| 1015 | /** |
||
| 1016 | * @deprecated |
||
| 1017 | * |
||
| 1018 | * Checks if the model exists in the database |
||
| 1019 | * |
||
| 1020 | * @return bool |
||
| 1021 | */ |
||
| 1022 | public function exists() |
||
| 1026 | |||
| 1027 | /** |
||
| 1028 | * Tells if this model instance has been persisted to the data layer. |
||
| 1029 | * |
||
| 1030 | * NOTE: this does not actually perform a check with the data layer |
||
| 1031 | * |
||
| 1032 | * @return bool |
||
| 1033 | */ |
||
| 1034 | public function persisted() |
||
| 1038 | |||
| 1039 | /** |
||
| 1040 | * Loads the model from the storage layer. |
||
| 1041 | * |
||
| 1042 | * @return self |
||
| 1043 | */ |
||
| 1044 | public function refresh() |
||
| 1061 | |||
| 1062 | /** |
||
| 1063 | * Loads values into the model. |
||
| 1064 | * |
||
| 1065 | * @param array $values values |
||
| 1066 | * |
||
| 1067 | * @return self |
||
| 1068 | */ |
||
| 1069 | public function refreshWith(array $values) |
||
| 1076 | |||
| 1077 | /** |
||
| 1078 | * Clears the cache for this model. |
||
| 1079 | * |
||
| 1080 | * @return self |
||
| 1081 | */ |
||
| 1082 | public function clearCache() |
||
| 1090 | |||
| 1091 | ///////////////////////////// |
||
| 1092 | // Relationships |
||
| 1093 | ///////////////////////////// |
||
| 1094 | |||
| 1095 | /** |
||
| 1096 | * @deprecated |
||
| 1097 | * |
||
| 1098 | * Gets the model object corresponding to a relation |
||
| 1099 | * WARNING no check is used to see if the model returned actually exists |
||
| 1100 | * |
||
| 1101 | * @param string $propertyName property |
||
| 1102 | * |
||
| 1103 | * @return Model |
||
| 1104 | */ |
||
| 1105 | public function relation($propertyName) |
||
| 1116 | |||
| 1117 | /** |
||
| 1118 | * Creates the parent side of a One-To-One relationship. |
||
| 1119 | * |
||
| 1120 | * @param string $model foreign model class |
||
| 1121 | * @param string $foreignKey identifying key on foreign model |
||
| 1122 | * @param string $localKey identifying key on local model |
||
| 1123 | * |
||
| 1124 | * @return Relation\Relation |
||
| 1125 | */ |
||
| 1126 | View Code Duplication | public function hasOne($model, $foreignKey = '', $localKey = '') |
|
| 1141 | |||
| 1142 | /** |
||
| 1143 | * Creates the child side of a One-To-One or One-To-Many relationship. |
||
| 1144 | * |
||
| 1145 | * @param string $model foreign model class |
||
| 1146 | * @param string $foreignKey identifying key on foreign model |
||
| 1147 | * @param string $localKey identifying key on local model |
||
| 1148 | * |
||
| 1149 | * @return Relation\Relation |
||
| 1150 | */ |
||
| 1151 | View Code Duplication | public function belongsTo($model, $foreignKey = '', $localKey = '') |
|
| 1166 | |||
| 1167 | /** |
||
| 1168 | * Creates the parent side of a Many-To-One or Many-To-Many relationship. |
||
| 1169 | * |
||
| 1170 | * @param string $model foreign model class |
||
| 1171 | * @param string $foreignKey identifying key on foreign model |
||
| 1172 | * @param string $localKey identifying key on local model |
||
| 1173 | * |
||
| 1174 | * @return Relation\Relation |
||
| 1175 | */ |
||
| 1176 | View Code Duplication | public function hasMany($model, $foreignKey = '', $localKey = '') |
|
| 1191 | |||
| 1192 | /** |
||
| 1193 | * Creates the child side of a Many-To-Many relationship. |
||
| 1194 | * |
||
| 1195 | * @param string $model foreign model class |
||
| 1196 | * @param string $foreignKey identifying key on foreign model |
||
| 1197 | * @param string $localKey identifying key on local model |
||
| 1198 | * |
||
| 1199 | * @return Relation\Relation |
||
| 1200 | */ |
||
| 1201 | View Code Duplication | public function belongsToMany($model, $foreignKey = '', $localKey = '') |
|
| 1216 | |||
| 1217 | ///////////////////////////// |
||
| 1218 | // Events |
||
| 1219 | ///////////////////////////// |
||
| 1220 | |||
| 1221 | /** |
||
| 1222 | * Gets the event dispatcher. |
||
| 1223 | * |
||
| 1224 | * @return EventDispatcher |
||
| 1225 | */ |
||
| 1226 | public static function getDispatcher($ignoreCache = false) |
||
| 1235 | |||
| 1236 | /** |
||
| 1237 | * Subscribes to a listener to an event. |
||
| 1238 | * |
||
| 1239 | * @param string $event event name |
||
| 1240 | * @param callable $listener |
||
| 1241 | * @param int $priority optional priority, higher #s get called first |
||
| 1242 | */ |
||
| 1243 | public static function listen($event, callable $listener, $priority = 0) |
||
| 1247 | |||
| 1248 | /** |
||
| 1249 | * Adds a listener to the model.creating and model.updating events. |
||
| 1250 | * |
||
| 1251 | * @param callable $listener |
||
| 1252 | * @param int $priority |
||
| 1253 | */ |
||
| 1254 | public static function saving(callable $listener, $priority = 0) |
||
| 1259 | |||
| 1260 | /** |
||
| 1261 | * Adds a listener to the model.created and model.updated events. |
||
| 1262 | * |
||
| 1263 | * @param callable $listener |
||
| 1264 | * @param int $priority |
||
| 1265 | */ |
||
| 1266 | public static function saved(callable $listener, $priority = 0) |
||
| 1271 | |||
| 1272 | /** |
||
| 1273 | * Adds a listener to the model.creating event. |
||
| 1274 | * |
||
| 1275 | * @param callable $listener |
||
| 1276 | * @param int $priority |
||
| 1277 | */ |
||
| 1278 | public static function creating(callable $listener, $priority = 0) |
||
| 1282 | |||
| 1283 | /** |
||
| 1284 | * Adds a listener to the model.created event. |
||
| 1285 | * |
||
| 1286 | * @param callable $listener |
||
| 1287 | * @param int $priority |
||
| 1288 | */ |
||
| 1289 | public static function created(callable $listener, $priority = 0) |
||
| 1293 | |||
| 1294 | /** |
||
| 1295 | * Adds a listener to the model.updating event. |
||
| 1296 | * |
||
| 1297 | * @param callable $listener |
||
| 1298 | * @param int $priority |
||
| 1299 | */ |
||
| 1300 | public static function updating(callable $listener, $priority = 0) |
||
| 1304 | |||
| 1305 | /** |
||
| 1306 | * Adds a listener to the model.updated event. |
||
| 1307 | * |
||
| 1308 | * @param callable $listener |
||
| 1309 | * @param int $priority |
||
| 1310 | */ |
||
| 1311 | public static function updated(callable $listener, $priority = 0) |
||
| 1315 | |||
| 1316 | /** |
||
| 1317 | * Adds a listener to the model.deleting event. |
||
| 1318 | * |
||
| 1319 | * @param callable $listener |
||
| 1320 | * @param int $priority |
||
| 1321 | */ |
||
| 1322 | public static function deleting(callable $listener, $priority = 0) |
||
| 1326 | |||
| 1327 | /** |
||
| 1328 | * Adds a listener to the model.deleted event. |
||
| 1329 | * |
||
| 1330 | * @param callable $listener |
||
| 1331 | * @param int $priority |
||
| 1332 | */ |
||
| 1333 | public static function deleted(callable $listener, $priority = 0) |
||
| 1337 | |||
| 1338 | /** |
||
| 1339 | * Dispatches an event. |
||
| 1340 | * |
||
| 1341 | * @param string $eventName |
||
| 1342 | * |
||
| 1343 | * @return ModelEvent |
||
| 1344 | */ |
||
| 1345 | protected function dispatch($eventName) |
||
| 1351 | |||
| 1352 | /** |
||
| 1353 | * Dispatches the given event and checks if it was successful. |
||
| 1354 | * |
||
| 1355 | * @param string $eventName |
||
| 1356 | * |
||
| 1357 | * @return bool true if the events were successfully propagated |
||
| 1358 | */ |
||
| 1359 | private function handleDispatch($eventName) |
||
| 1365 | |||
| 1366 | ///////////////////////////// |
||
| 1367 | // Validation |
||
| 1368 | ///////////////////////////// |
||
| 1369 | |||
| 1370 | /** |
||
| 1371 | * Validates and marshals a value to storage. |
||
| 1372 | * |
||
| 1373 | * @param array $property |
||
| 1374 | * @param string $propertyName |
||
| 1375 | * @param mixed $value |
||
| 1376 | * |
||
| 1377 | * @return bool |
||
| 1378 | */ |
||
| 1379 | private function filterAndValidate(array $property, $propertyName, &$value) |
||
| 1399 | |||
| 1400 | /** |
||
| 1401 | * Validates a value for a property. |
||
| 1402 | * |
||
| 1403 | * @param array $property |
||
| 1404 | * @param string $propertyName |
||
| 1405 | * @param mixed $value |
||
| 1406 | * |
||
| 1407 | * @return array |
||
| 1408 | */ |
||
| 1409 | private function validate(array $property, $propertyName, $value) |
||
| 1429 | |||
| 1430 | /** |
||
| 1431 | * Checks if a value is unique for a property. |
||
| 1432 | * |
||
| 1433 | * @param array $property |
||
| 1434 | * @param string $propertyName |
||
| 1435 | * @param mixed $value |
||
| 1436 | * |
||
| 1437 | * @return bool |
||
| 1438 | */ |
||
| 1439 | private function checkUniqueness(array $property, $propertyName, $value) |
||
| 1453 | |||
| 1454 | /** |
||
| 1455 | * Gets the marshaled default value for a property (if set). |
||
| 1456 | * |
||
| 1457 | * @param string $property |
||
| 1458 | * |
||
| 1459 | * @return mixed |
||
| 1460 | */ |
||
| 1461 | private function getPropertyDefault(array $property) |
||
| 1465 | } |
||
| 1466 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.