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 |
||
| 30 | abstract class Model implements \ArrayAccess |
||
| 31 | { |
||
| 32 | const IMMUTABLE = 0; |
||
| 33 | const MUTABLE_CREATE_ONLY = 1; |
||
| 34 | const MUTABLE = 2; |
||
| 35 | |||
| 36 | const TYPE_STRING = 'string'; |
||
| 37 | const TYPE_NUMBER = 'number'; // DEPRECATED |
||
| 38 | const TYPE_INTEGER = 'integer'; |
||
| 39 | const TYPE_FLOAT = 'float'; |
||
| 40 | const TYPE_BOOLEAN = 'boolean'; |
||
| 41 | const TYPE_DATE = 'date'; |
||
| 42 | const TYPE_OBJECT = 'object'; |
||
| 43 | const TYPE_ARRAY = 'array'; |
||
| 44 | |||
| 45 | const ERROR_REQUIRED_FIELD_MISSING = 'required_field_missing'; |
||
| 46 | const ERROR_VALIDATION_FAILED = 'validation_failed'; |
||
| 47 | const ERROR_NOT_UNIQUE = 'not_unique'; |
||
| 48 | |||
| 49 | const DEFAULT_ID_PROPERTY = 'id'; |
||
| 50 | |||
| 51 | ///////////////////////////// |
||
| 52 | // Model visible variables |
||
| 53 | ///////////////////////////// |
||
| 54 | |||
| 55 | /** |
||
| 56 | * List of model ID property names. |
||
| 57 | * |
||
| 58 | * @var array |
||
| 59 | */ |
||
| 60 | protected static $ids = [self::DEFAULT_ID_PROPERTY]; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Property definitions expressed as a key-value map with |
||
| 64 | * property names as the keys. |
||
| 65 | * i.e. ['enabled' => ['type' => Model::TYPE_BOOLEAN]]. |
||
| 66 | * |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | protected static $properties = []; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var Container |
||
| 73 | */ |
||
| 74 | protected static $injectedApp; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var array |
||
| 78 | */ |
||
| 79 | protected static $dispatchers; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var number|string|false |
||
| 83 | */ |
||
| 84 | protected $_id; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | protected $_ids; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var Container |
||
| 93 | */ |
||
| 94 | protected $app; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var array |
||
| 98 | */ |
||
| 99 | protected $_values = []; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var array |
||
| 103 | */ |
||
| 104 | protected $_unsaved = []; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var bool |
||
| 108 | */ |
||
| 109 | protected $_persisted = false; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @var array |
||
| 113 | */ |
||
| 114 | protected $_relationships = []; |
||
| 115 | |||
| 116 | ///////////////////////////// |
||
| 117 | // Base model variables |
||
| 118 | ///////////////////////////// |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @var array |
||
| 122 | */ |
||
| 123 | private static $propertyDefinitionBase = [ |
||
| 124 | 'type' => self::TYPE_STRING, |
||
| 125 | 'mutable' => self::MUTABLE, |
||
| 126 | 'null' => false, |
||
| 127 | 'unique' => false, |
||
| 128 | 'required' => false, |
||
| 129 | ]; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @var array |
||
| 133 | */ |
||
| 134 | private static $defaultIDProperty = [ |
||
| 135 | 'type' => self::TYPE_INTEGER, |
||
| 136 | 'mutable' => self::IMMUTABLE, |
||
| 137 | ]; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @var array |
||
| 141 | */ |
||
| 142 | private static $timestampProperties = [ |
||
| 143 | 'created_at' => [ |
||
| 144 | 'type' => self::TYPE_DATE, |
||
| 145 | 'validate' => 'timestamp|db_timestamp', |
||
| 146 | ], |
||
| 147 | 'updated_at' => [ |
||
| 148 | 'type' => self::TYPE_DATE, |
||
| 149 | 'validate' => 'timestamp|db_timestamp', |
||
| 150 | ], |
||
| 151 | ]; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var array |
||
| 155 | */ |
||
| 156 | private static $initialized = []; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var DriverInterface |
||
| 160 | */ |
||
| 161 | private static $driver; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var array |
||
| 165 | */ |
||
| 166 | private static $accessors = []; |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @var array |
||
| 170 | */ |
||
| 171 | private static $mutators = []; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @var bool |
||
| 175 | */ |
||
| 176 | private $_ignoreUnsaved; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Creates a new model object. |
||
| 180 | * |
||
| 181 | * @param array|string|Model|false $id ordered array of ids or comma-separated id string |
||
| 182 | * @param array $values optional key-value map to pre-seed model |
||
| 183 | */ |
||
| 184 | public function __construct($id = false, array $values = []) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Performs initialization on this model. |
||
| 228 | */ |
||
| 229 | private function init() |
||
| 238 | |||
| 239 | /** |
||
| 240 | * The initialize() method is called once per model. It's used |
||
| 241 | * to perform any one-off tasks before the model gets |
||
| 242 | * constructed. This is a great place to add any model |
||
| 243 | * properties. When extending this method be sure to call |
||
| 244 | * parent::initialize() as some important stuff happens here. |
||
| 245 | * If extending this method to add properties then you should |
||
| 246 | * call parent::initialize() after adding any properties. |
||
| 247 | */ |
||
| 248 | protected function initialize() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Installs the `created_at` and `updated_at` properties. |
||
| 276 | */ |
||
| 277 | private function installAutoTimestamps() |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Injects a DI container. |
||
| 294 | * |
||
| 295 | * @param Container $app |
||
| 296 | */ |
||
| 297 | public static function inject(Container $app) |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Gets the DI container used for this model. |
||
| 304 | * |
||
| 305 | * @return Container |
||
| 306 | */ |
||
| 307 | public function getApp() |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Sets the driver for all models. |
||
| 314 | * |
||
| 315 | * @param DriverInterface $driver |
||
| 316 | */ |
||
| 317 | public static function setDriver(DriverInterface $driver) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Gets the driver for all models. |
||
| 324 | * |
||
| 325 | * @return DriverInterface |
||
| 326 | * |
||
| 327 | * @throws DriverMissingException when a driver has not been set yet |
||
| 328 | */ |
||
| 329 | public static function getDriver() |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Clears the driver for all models. |
||
| 340 | */ |
||
| 341 | public static function clearDriver() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Gets the name of the model, i.e. User. |
||
| 348 | * |
||
| 349 | * @return string |
||
| 350 | */ |
||
| 351 | public static function modelName() |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Gets the model ID. |
||
| 361 | * |
||
| 362 | * @return string|number|false ID |
||
| 363 | */ |
||
| 364 | public function id() |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Gets a key-value map of the model ID. |
||
| 371 | * |
||
| 372 | * @return array ID map |
||
| 373 | */ |
||
| 374 | public function ids() |
||
| 378 | |||
| 379 | ///////////////////////////// |
||
| 380 | // Magic Methods |
||
| 381 | ///////////////////////////// |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Converts the model into a string. |
||
| 385 | * |
||
| 386 | * @return string |
||
| 387 | */ |
||
| 388 | public function __toString() |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Shortcut to a get() call for a given property. |
||
| 395 | * |
||
| 396 | * @param string $name |
||
| 397 | * |
||
| 398 | * @return mixed |
||
| 399 | */ |
||
| 400 | public function __get($name) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Sets an unsaved value. |
||
| 409 | * |
||
| 410 | * @param string $name |
||
| 411 | * @param mixed $value |
||
| 412 | */ |
||
| 413 | public function __set($name, $value) |
||
| 428 | |||
| 429 | /** |
||
| 430 | * Checks if an unsaved value or property exists by this name. |
||
| 431 | * |
||
| 432 | * @param string $name |
||
| 433 | * |
||
| 434 | * @return bool |
||
| 435 | */ |
||
| 436 | public function __isset($name) |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Unsets an unsaved value. |
||
| 443 | * |
||
| 444 | * @param string $name |
||
| 445 | */ |
||
| 446 | public function __unset($name) |
||
| 457 | |||
| 458 | ///////////////////////////// |
||
| 459 | // ArrayAccess Interface |
||
| 460 | ///////////////////////////// |
||
| 461 | |||
| 462 | public function offsetExists($offset) |
||
| 466 | |||
| 467 | public function offsetGet($offset) |
||
| 471 | |||
| 472 | public function offsetSet($offset, $value) |
||
| 476 | |||
| 477 | public function offsetUnset($offset) |
||
| 481 | |||
| 482 | public static function __callStatic($name, $parameters) |
||
| 489 | |||
| 490 | ///////////////////////////// |
||
| 491 | // Property Definitions |
||
| 492 | ///////////////////////////// |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Gets all the property definitions for the model. |
||
| 496 | * |
||
| 497 | * @return array key-value map of properties |
||
| 498 | */ |
||
| 499 | public static function getProperties() |
||
| 503 | |||
| 504 | /** |
||
| 505 | * Gets a property defition for the model. |
||
| 506 | * |
||
| 507 | * @param string $property property to lookup |
||
| 508 | * |
||
| 509 | * @return array|null property |
||
| 510 | */ |
||
| 511 | public static function getProperty($property) |
||
| 515 | |||
| 516 | /** |
||
| 517 | * Gets the names of the model ID properties. |
||
| 518 | * |
||
| 519 | * @return array |
||
| 520 | */ |
||
| 521 | public static function getIDProperties() |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Checks if the model has a property. |
||
| 528 | * |
||
| 529 | * @param string $property property |
||
| 530 | * |
||
| 531 | * @return bool has property |
||
| 532 | */ |
||
| 533 | public static function hasProperty($property) |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Gets the mutator method name for a given proeprty name. |
||
| 540 | * Looks for methods in the form of `setPropertyValue`. |
||
| 541 | * i.e. the mutator for `last_name` would be `setLastNameValue`. |
||
| 542 | * |
||
| 543 | * @param string $property property |
||
| 544 | * |
||
| 545 | * @return string|false method name if it exists |
||
| 546 | */ |
||
| 547 | View Code Duplication | public static function getMutator($property) |
|
| 565 | |||
| 566 | /** |
||
| 567 | * Gets the accessor method name for a given proeprty name. |
||
| 568 | * Looks for methods in the form of `getPropertyValue`. |
||
| 569 | * i.e. the accessor for `last_name` would be `getLastNameValue`. |
||
| 570 | * |
||
| 571 | * @param string $property property |
||
| 572 | * |
||
| 573 | * @return string|false method name if it exists |
||
| 574 | */ |
||
| 575 | View Code Duplication | public static function getAccessor($property) |
|
| 593 | |||
| 594 | ///////////////////////////// |
||
| 595 | // CRUD Operations |
||
| 596 | ///////////////////////////// |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Saves the model. |
||
| 600 | * |
||
| 601 | * @return bool true when the operation was successful |
||
| 602 | */ |
||
| 603 | public function save() |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Creates a new model. |
||
| 614 | * |
||
| 615 | * @param array $data optional key-value properties to set |
||
| 616 | * |
||
| 617 | * @return bool true when the operation was successful |
||
| 618 | * |
||
| 619 | * @throws BadMethodCallException when called on an existing model |
||
| 620 | */ |
||
| 621 | public function create(array $data = []) |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Ignores unsaved values when fetching the next value. |
||
| 709 | * |
||
| 710 | * @return self |
||
| 711 | */ |
||
| 712 | public function ignoreUnsaved() |
||
| 718 | |||
| 719 | /** |
||
| 720 | * Fetches property values from the model. |
||
| 721 | * |
||
| 722 | * This method looks up values in this order: |
||
| 723 | * IDs, local cache, unsaved values, storage layer, defaults |
||
| 724 | * |
||
| 725 | * @param array $properties list of property names to fetch values of |
||
| 726 | * |
||
| 727 | * @return array |
||
| 728 | */ |
||
| 729 | public function get(array $properties) |
||
| 774 | |||
| 775 | /** |
||
| 776 | * Populates a newly created model with its ID. |
||
| 777 | */ |
||
| 778 | protected function getNewID() |
||
| 798 | |||
| 799 | /** |
||
| 800 | * Sets a collection values on the model from an untrusted input. |
||
| 801 | * |
||
| 802 | * @param array $values |
||
| 803 | * |
||
| 804 | * @throws MassAssignmentException when assigning a value that is protected or not whitelisted |
||
| 805 | * |
||
| 806 | * @return self |
||
| 807 | */ |
||
| 808 | public function setValues($values) |
||
| 828 | |||
| 829 | /** |
||
| 830 | * Converts the model to an array. |
||
| 831 | * |
||
| 832 | * @return array |
||
| 833 | */ |
||
| 834 | public function toArray() |
||
| 865 | |||
| 866 | /** |
||
| 867 | * Updates the model. |
||
| 868 | * |
||
| 869 | * @param array $data optional key-value properties to set |
||
| 870 | * |
||
| 871 | * @return bool true when the operation was successful |
||
| 872 | * |
||
| 873 | * @throws BadMethodCallException when not called on an existing model |
||
| 874 | */ |
||
| 875 | public function set(array $data = []) |
||
| 939 | |||
| 940 | /** |
||
| 941 | * Delete the model. |
||
| 942 | * |
||
| 943 | * @return bool true when the operation was successful |
||
| 944 | */ |
||
| 945 | public function delete() |
||
| 969 | |||
| 970 | ///////////////////////////// |
||
| 971 | // Queries |
||
| 972 | ///////////////////////////// |
||
| 973 | |||
| 974 | /** |
||
| 975 | * Generates a new query instance. |
||
| 976 | * |
||
| 977 | * @return Query |
||
| 978 | */ |
||
| 979 | public static function query() |
||
| 988 | |||
| 989 | /** |
||
| 990 | * Finds a single instance of a model given it's ID. |
||
| 991 | * |
||
| 992 | * @param mixed $id |
||
| 993 | * |
||
| 994 | * @return Model|false |
||
| 995 | */ |
||
| 996 | public static function find($id) |
||
| 1006 | |||
| 1007 | /** |
||
| 1008 | * Finds a single instance of a model given it's ID or throws an exception. |
||
| 1009 | * |
||
| 1010 | * @param mixed $id |
||
| 1011 | * |
||
| 1012 | * @return Model |
||
| 1013 | * |
||
| 1014 | * @throws ModelNotFoundException when a model could not be found |
||
| 1015 | */ |
||
| 1016 | public static function findOrFail($id) |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * @deprecated |
||
| 1028 | * |
||
| 1029 | * Checks if the model exists in the database |
||
| 1030 | * |
||
| 1031 | * @return bool |
||
| 1032 | */ |
||
| 1033 | public function exists() |
||
| 1037 | |||
| 1038 | /** |
||
| 1039 | * Tells if this model instance has been persisted to the data layer. |
||
| 1040 | * |
||
| 1041 | * NOTE: this does not actually perform a check with the data layer |
||
| 1042 | * |
||
| 1043 | * @return bool |
||
| 1044 | */ |
||
| 1045 | public function persisted() |
||
| 1049 | |||
| 1050 | /** |
||
| 1051 | * Loads the model from the storage layer. |
||
| 1052 | * |
||
| 1053 | * @return self |
||
| 1054 | */ |
||
| 1055 | public function refresh() |
||
| 1072 | |||
| 1073 | /** |
||
| 1074 | * Loads values into the model. |
||
| 1075 | * |
||
| 1076 | * @param array $values values |
||
| 1077 | * |
||
| 1078 | * @return self |
||
| 1079 | */ |
||
| 1080 | public function refreshWith(array $values) |
||
| 1087 | |||
| 1088 | /** |
||
| 1089 | * Clears the cache for this model. |
||
| 1090 | * |
||
| 1091 | * @return self |
||
| 1092 | */ |
||
| 1093 | public function clearCache() |
||
| 1101 | |||
| 1102 | ///////////////////////////// |
||
| 1103 | // Relationships |
||
| 1104 | ///////////////////////////// |
||
| 1105 | |||
| 1106 | /** |
||
| 1107 | * @deprecated |
||
| 1108 | * |
||
| 1109 | * Gets the model for a has-one relationship |
||
| 1110 | * |
||
| 1111 | * @param string $k property |
||
| 1112 | * |
||
| 1113 | * @return Model|null |
||
| 1114 | */ |
||
| 1115 | public function relation($k) |
||
| 1130 | |||
| 1131 | /** |
||
| 1132 | * @deprecated |
||
| 1133 | * |
||
| 1134 | * Sets the model for a has-one relationship |
||
| 1135 | * |
||
| 1136 | * @param string $k |
||
| 1137 | * @param Model $model |
||
| 1138 | * |
||
| 1139 | * @return self |
||
| 1140 | */ |
||
| 1141 | public function setRelation($k, Model $model) |
||
| 1148 | |||
| 1149 | /** |
||
| 1150 | * Creates the parent side of a One-To-One relationship. |
||
| 1151 | * |
||
| 1152 | * @param string $model foreign model class |
||
| 1153 | * @param string $foreignKey identifying key on foreign model |
||
| 1154 | * @param string $localKey identifying key on local model |
||
| 1155 | * |
||
| 1156 | * @return Relation\Relation |
||
| 1157 | */ |
||
| 1158 | View Code Duplication | public function hasOne($model, $foreignKey = '', $localKey = '') |
|
| 1173 | |||
| 1174 | /** |
||
| 1175 | * Creates the child side of a One-To-One or One-To-Many relationship. |
||
| 1176 | * |
||
| 1177 | * @param string $model foreign model class |
||
| 1178 | * @param string $foreignKey identifying key on foreign model |
||
| 1179 | * @param string $localKey identifying key on local model |
||
| 1180 | * |
||
| 1181 | * @return Relation\Relation |
||
| 1182 | */ |
||
| 1183 | View Code Duplication | public function belongsTo($model, $foreignKey = '', $localKey = '') |
|
| 1198 | |||
| 1199 | /** |
||
| 1200 | * Creates the parent side of a Many-To-One or Many-To-Many relationship. |
||
| 1201 | * |
||
| 1202 | * @param string $model foreign model class |
||
| 1203 | * @param string $foreignKey identifying key on foreign model |
||
| 1204 | * @param string $localKey identifying key on local model |
||
| 1205 | * |
||
| 1206 | * @return Relation\Relation |
||
| 1207 | */ |
||
| 1208 | View Code Duplication | public function hasMany($model, $foreignKey = '', $localKey = '') |
|
| 1223 | |||
| 1224 | /** |
||
| 1225 | * Creates the child side of a Many-To-Many relationship. |
||
| 1226 | * |
||
| 1227 | * @param string $model foreign model class |
||
| 1228 | * @param string $foreignKey identifying key on foreign model |
||
| 1229 | * @param string $localKey identifying key on local model |
||
| 1230 | * |
||
| 1231 | * @return Relation\Relation |
||
| 1232 | */ |
||
| 1233 | View Code Duplication | public function belongsToMany($model, $foreignKey = '', $localKey = '') |
|
| 1248 | |||
| 1249 | ///////////////////////////// |
||
| 1250 | // Events |
||
| 1251 | ///////////////////////////// |
||
| 1252 | |||
| 1253 | /** |
||
| 1254 | * Gets the event dispatcher. |
||
| 1255 | * |
||
| 1256 | * @return EventDispatcher |
||
| 1257 | */ |
||
| 1258 | public static function getDispatcher($ignoreCache = false) |
||
| 1267 | |||
| 1268 | /** |
||
| 1269 | * Subscribes to a listener to an event. |
||
| 1270 | * |
||
| 1271 | * @param string $event event name |
||
| 1272 | * @param callable $listener |
||
| 1273 | * @param int $priority optional priority, higher #s get called first |
||
| 1274 | */ |
||
| 1275 | public static function listen($event, callable $listener, $priority = 0) |
||
| 1279 | |||
| 1280 | /** |
||
| 1281 | * Adds a listener to the model.creating and model.updating events. |
||
| 1282 | * |
||
| 1283 | * @param callable $listener |
||
| 1284 | * @param int $priority |
||
| 1285 | */ |
||
| 1286 | public static function saving(callable $listener, $priority = 0) |
||
| 1291 | |||
| 1292 | /** |
||
| 1293 | * Adds a listener to the model.created and model.updated events. |
||
| 1294 | * |
||
| 1295 | * @param callable $listener |
||
| 1296 | * @param int $priority |
||
| 1297 | */ |
||
| 1298 | public static function saved(callable $listener, $priority = 0) |
||
| 1303 | |||
| 1304 | /** |
||
| 1305 | * Adds a listener to the model.creating event. |
||
| 1306 | * |
||
| 1307 | * @param callable $listener |
||
| 1308 | * @param int $priority |
||
| 1309 | */ |
||
| 1310 | public static function creating(callable $listener, $priority = 0) |
||
| 1314 | |||
| 1315 | /** |
||
| 1316 | * Adds a listener to the model.created event. |
||
| 1317 | * |
||
| 1318 | * @param callable $listener |
||
| 1319 | * @param int $priority |
||
| 1320 | */ |
||
| 1321 | public static function created(callable $listener, $priority = 0) |
||
| 1325 | |||
| 1326 | /** |
||
| 1327 | * Adds a listener to the model.updating event. |
||
| 1328 | * |
||
| 1329 | * @param callable $listener |
||
| 1330 | * @param int $priority |
||
| 1331 | */ |
||
| 1332 | public static function updating(callable $listener, $priority = 0) |
||
| 1336 | |||
| 1337 | /** |
||
| 1338 | * Adds a listener to the model.updated event. |
||
| 1339 | * |
||
| 1340 | * @param callable $listener |
||
| 1341 | * @param int $priority |
||
| 1342 | */ |
||
| 1343 | public static function updated(callable $listener, $priority = 0) |
||
| 1347 | |||
| 1348 | /** |
||
| 1349 | * Adds a listener to the model.deleting event. |
||
| 1350 | * |
||
| 1351 | * @param callable $listener |
||
| 1352 | * @param int $priority |
||
| 1353 | */ |
||
| 1354 | public static function deleting(callable $listener, $priority = 0) |
||
| 1358 | |||
| 1359 | /** |
||
| 1360 | * Adds a listener to the model.deleted event. |
||
| 1361 | * |
||
| 1362 | * @param callable $listener |
||
| 1363 | * @param int $priority |
||
| 1364 | */ |
||
| 1365 | public static function deleted(callable $listener, $priority = 0) |
||
| 1369 | |||
| 1370 | /** |
||
| 1371 | * Dispatches an event. |
||
| 1372 | * |
||
| 1373 | * @param string $eventName |
||
| 1374 | * |
||
| 1375 | * @return ModelEvent |
||
| 1376 | */ |
||
| 1377 | protected function dispatch($eventName) |
||
| 1383 | |||
| 1384 | /** |
||
| 1385 | * Dispatches the given event and checks if it was successful. |
||
| 1386 | * |
||
| 1387 | * @param string $eventName |
||
| 1388 | * |
||
| 1389 | * @return bool true if the events were successfully propagated |
||
| 1390 | */ |
||
| 1391 | private function handleDispatch($eventName) |
||
| 1397 | |||
| 1398 | ///////////////////////////// |
||
| 1399 | // Validation |
||
| 1400 | ///////////////////////////// |
||
| 1401 | |||
| 1402 | /** |
||
| 1403 | * Validates and marshals a value to storage. |
||
| 1404 | * |
||
| 1405 | * @param array $property |
||
| 1406 | * @param string $propertyName |
||
| 1407 | * @param mixed $value |
||
| 1408 | * |
||
| 1409 | * @return bool |
||
| 1410 | */ |
||
| 1411 | private function filterAndValidate(array $property, $propertyName, &$value) |
||
| 1431 | |||
| 1432 | /** |
||
| 1433 | * Validates a value for a property. |
||
| 1434 | * |
||
| 1435 | * @param array $property |
||
| 1436 | * @param string $propertyName |
||
| 1437 | * @param mixed $value |
||
| 1438 | * |
||
| 1439 | * @return array |
||
| 1440 | */ |
||
| 1441 | private function validate(array $property, $propertyName, $value) |
||
| 1461 | |||
| 1462 | /** |
||
| 1463 | * Checks if a value is unique for a property. |
||
| 1464 | * |
||
| 1465 | * @param array $property |
||
| 1466 | * @param string $propertyName |
||
| 1467 | * @param mixed $value |
||
| 1468 | * |
||
| 1469 | * @return bool |
||
| 1470 | */ |
||
| 1471 | private function checkUniqueness(array $property, $propertyName, $value) |
||
| 1486 | |||
| 1487 | /** |
||
| 1488 | * Gets the marshaled default value for a property (if set). |
||
| 1489 | * |
||
| 1490 | * @param string $property |
||
| 1491 | * |
||
| 1492 | * @return mixed |
||
| 1493 | */ |
||
| 1494 | private function getPropertyDefault(array $property) |
||
| 1498 | } |
||
| 1499 |
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.