Complex classes like ActiveRecord 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 ActiveRecord, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 66 | abstract class ActiveRecord |
||
| 67 | { |
||
| 68 | /** |
||
| 69 | * The object ID. |
||
| 70 | * |
||
| 71 | * @var int |
||
| 72 | * |
||
| 73 | * @since 1.0 |
||
| 74 | */ |
||
| 75 | protected $ID; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * The last database query run by this object. Useful for tracing an error. |
||
| 79 | * |
||
| 80 | * @var string |
||
| 81 | * |
||
| 82 | * @since 1.0 |
||
| 83 | */ |
||
| 84 | protected $lastQuery; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * The version number of the object, used for locking mechanism. |
||
| 88 | * |
||
| 89 | * @var \Alpha\Model\Type\Integer |
||
| 90 | * |
||
| 91 | * @since 1.0 |
||
| 92 | */ |
||
| 93 | protected $version_num; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * The timestamp of creation. |
||
| 97 | * |
||
| 98 | * @var \Alpha\Model\Type\Timestamp |
||
| 99 | * |
||
| 100 | * @since 1.0 |
||
| 101 | */ |
||
| 102 | protected $created_ts; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * The ID of the person who created this record. |
||
| 106 | * |
||
| 107 | * @var \Alpha\Model\Type\Integer |
||
| 108 | * |
||
| 109 | * @since 1.0 |
||
| 110 | */ |
||
| 111 | protected $created_by; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * The timestamp of the last update. |
||
| 115 | * |
||
| 116 | * @var \Alpha\Model\Type\Timestamp |
||
| 117 | * |
||
| 118 | * @since 1.0 |
||
| 119 | */ |
||
| 120 | protected $updated_ts; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * The ID of the person who last updated this record. |
||
| 124 | * |
||
| 125 | * @var \Alpha\Model\Type\Integer |
||
| 126 | * |
||
| 127 | * @since 1.0 |
||
| 128 | */ |
||
| 129 | protected $updated_by; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * An array of the names of all of the default attributes of a persistent Record defined in this class. |
||
| 133 | * |
||
| 134 | * @var array |
||
| 135 | * |
||
| 136 | * @since 1.0 |
||
| 137 | */ |
||
| 138 | protected $defaultAttributes = array('ID', 'lastQuery', 'version_num', 'dataLabels', 'created_ts', 'created_by', 'updated_ts', 'updated_by', 'defaultAttributes', 'transientAttributes', 'uniqueAttributes', 'TABLE_NAME', 'logger'); |
||
| 139 | |||
| 140 | /** |
||
| 141 | * An array of the names of all of the transient attributes of a persistent Record which are not saved to the DB. |
||
| 142 | * |
||
| 143 | * @var array |
||
| 144 | * |
||
| 145 | * @since 1.0 |
||
| 146 | */ |
||
| 147 | protected $transientAttributes = array('lastQuery', 'dataLabels', 'defaultAttributes', 'transientAttributes', 'uniqueAttributes', 'TABLE_NAME', 'logger'); |
||
| 148 | |||
| 149 | /** |
||
| 150 | * An array of the uniquely-constained attributes of this persistent record. |
||
| 151 | * |
||
| 152 | * @var array |
||
| 153 | * |
||
| 154 | * @since 1.0 |
||
| 155 | */ |
||
| 156 | protected $uniqueAttributes = array(); |
||
| 157 | |||
| 158 | /** |
||
| 159 | * An array of the data labels used for displaying class attributes. |
||
| 160 | * |
||
| 161 | * @var array |
||
| 162 | * |
||
| 163 | * @since 1.0 |
||
| 164 | */ |
||
| 165 | protected $dataLabels = array(); |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Trace logger. |
||
| 169 | * |
||
| 170 | * @var \Alpha\Util\Logging\Logger |
||
| 171 | * |
||
| 172 | * @since 1.0 |
||
| 173 | */ |
||
| 174 | private static $logger = null; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Determines if we will maintain a _history table for this record (default is false). |
||
| 178 | * |
||
| 179 | * @var bool |
||
| 180 | * |
||
| 181 | * @since 1.2 |
||
| 182 | */ |
||
| 183 | private $maintainHistory = false; |
||
| 184 | |||
| 185 | /** |
||
| 186 | * The constructor which sets up some housekeeping attributes. |
||
| 187 | * |
||
| 188 | * @since 1.0 |
||
| 189 | */ |
||
| 190 | public function __construct() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Disconnects the current database connection if one exists. |
||
| 214 | * |
||
| 215 | * @since 1.0 |
||
| 216 | */ |
||
| 217 | public static function disconnect() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Returns a 2d array, where each element in the array is another array representing a database row. |
||
| 227 | * |
||
| 228 | * @param string $sqlQuery |
||
| 229 | * |
||
| 230 | * @return array |
||
| 231 | * |
||
| 232 | * @since 1.1 |
||
| 233 | * |
||
| 234 | * @throws \Alpha\Exception\CustomQueryException |
||
| 235 | */ |
||
| 236 | public function query($sqlQuery) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Populates the child object with the properties retrived from the database for the object $ID. |
||
| 253 | * |
||
| 254 | * @param int $ID The object ID of the business object to load. |
||
| 255 | * @param int $version Optionaly, provide the version to load that version from the [tablename]_history table. |
||
| 256 | * |
||
| 257 | * @since 1.0 |
||
| 258 | * |
||
| 259 | * @throws \Alpha\Exception\RecordNotFoundException |
||
| 260 | */ |
||
| 261 | public function load($ID, $version = 0) |
||
| 262 | { |
||
| 263 | self::$logger->debug('>>load(ID=['.$ID.'], version=['.$version.'])'); |
||
| 264 | |||
| 265 | if (method_exists($this, 'before_load_callback')) { |
||
| 266 | $this->{'before_load_callback'}(); |
||
| 267 | } |
||
| 268 | |||
| 269 | $config = ConfigProvider::getInstance(); |
||
| 270 | |||
| 271 | $this->ID = $ID; |
||
| 272 | |||
| 273 | if ($config->get('cache.provider.name') != '' && $this->loadFromCache()) { |
||
| 274 | // Record was found in cache |
||
| 275 | } else { |
||
| 276 | $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); |
||
| 277 | $provider->setRecord($this); |
||
| 278 | $provider->load($ID, $version); |
||
| 279 | |||
| 280 | if ($config->get('cache.provider.name') != '') { |
||
| 281 | $this->addToCache(); |
||
| 282 | } |
||
| 283 | } |
||
| 284 | |||
| 285 | $this->setEnumOptions(); |
||
| 286 | |||
| 287 | if (method_exists($this, 'after_load_callback')) { |
||
| 288 | $this->{'after_load_callback'}(); |
||
| 289 | } |
||
| 290 | |||
| 291 | self::$logger->debug('<<load'); |
||
| 292 | } |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Load all old versions (if any) of this record from the [tablename]_history table. |
||
| 296 | * |
||
| 297 | * @param int $ID The object ID of the record to load. |
||
| 298 | * |
||
| 299 | * @return array An array containing objects of this type of record object, order by version. |
||
| 300 | * |
||
| 301 | * @since 2.0 |
||
| 302 | * |
||
| 303 | * @throws \Alpha\Exception\RecordFoundException |
||
| 304 | */ |
||
| 305 | public function loadAllOldVersions($ID) |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Populates the child object from the database table by the given attribute value. |
||
| 322 | * |
||
| 323 | * @param string $attribute The name of the attribute to load the object by. |
||
| 324 | * @param string $value The value of the attribute to load the object by. |
||
| 325 | * @param bool $ignoreClassType Default is false, set to true if you want to load from overloaded tables and ignore the class type |
||
| 326 | * @param array $loadAttributes The attributes to load from the database to this object (leave blank to load all attributes) |
||
| 327 | * |
||
| 328 | * @since 1.0 |
||
| 329 | * |
||
| 330 | * @throws \Alpha\Exception\RecordNotFoundException |
||
| 331 | */ |
||
| 332 | public function loadByAttribute($attribute, $value, $ignoreClassType = false, $loadAttributes = array()) |
||
| 333 | { |
||
| 334 | self::$logger->debug('>>loadByAttribute(attribute=['.$attribute.'], value=['.$value.'], ignoreClassType=['.$ignoreClassType.'], |
||
| 335 | loadAttributes=['.var_export($loadAttributes, true).'])'); |
||
| 336 | |||
| 337 | if (method_exists($this, 'before_loadByAttribute_callback')) { |
||
| 338 | $this->{'before_loadByAttribute_callback'}(); |
||
| 339 | } |
||
| 340 | |||
| 341 | $config = ConfigProvider::getInstance(); |
||
| 342 | |||
| 343 | $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); |
||
| 344 | $provider->setRecord($this); |
||
| 345 | $provider->loadByAttribute($attribute, $value, $ignoreClassType, $loadAttributes); |
||
| 346 | |||
| 347 | $this->setEnumOptions(); |
||
| 348 | |||
| 349 | if ($config->get('cache.provider.name') != '' && count($loadAttributes) == 0) { // we will only cache fully-populated records |
||
| 350 | $this->addToCache(); |
||
| 351 | } |
||
| 352 | |||
| 353 | if (method_exists($this, 'after_loadByAttribute_callback')) { |
||
| 354 | $this->{'after_loadByAttribute_callback'}(); |
||
| 355 | } |
||
| 356 | |||
| 357 | self::$logger->debug('<<loadByAttribute'); |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Loads all of the objects of this class into an array which is returned. |
||
| 362 | * |
||
| 363 | * @param int $start The start of the SQL LIMIT clause, useful for pagination. |
||
| 364 | * @param int $limit The amount (limit) of objects to load, useful for pagination. |
||
| 365 | * @param string $orderBy The name of the field to sort the objects by. |
||
| 366 | * @param string $order The order to sort the objects by. |
||
| 367 | * @param bool $ignoreClassType Default is false, set to true if you want to load from overloaded tables and ignore the class type |
||
| 368 | * |
||
| 369 | * @return array An array containing objects of this type of business object. |
||
| 370 | * |
||
| 371 | * @since 1.0 |
||
| 372 | * |
||
| 373 | * @throws \Alpha\Exception\RecordNotFoundException |
||
| 374 | */ |
||
| 375 | public function loadAll($start = 0, $limit = 0, $orderBy = 'ID', $order = 'ASC', $ignoreClassType = false) |
||
| 376 | { |
||
| 377 | self::$logger->debug('>>loadAll(start=['.$start.'], limit=['.$limit.'], orderBy=['.$orderBy.'], order=['.$order.'], ignoreClassType=['.$ignoreClassType.']'); |
||
| 378 | |||
| 379 | if (method_exists($this, 'before_loadAll_callback')) { |
||
| 380 | $this->{'before_loadAll_callback'}(); |
||
| 381 | } |
||
| 382 | |||
| 383 | $config = ConfigProvider::getInstance(); |
||
| 384 | |||
| 385 | $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); |
||
| 386 | $provider->setRecord($this); |
||
| 387 | $objects = $provider->loadAll($start, $limit, $orderBy, $order, $ignoreClassType); |
||
| 388 | |||
| 389 | if (method_exists($this, 'after_loadAll_callback')) { |
||
| 390 | $this->{'after_loadAll_callback'}(); |
||
| 391 | } |
||
| 392 | |||
| 393 | self::$logger->debug('<<loadAll ['.count($objects).']'); |
||
| 394 | |||
| 395 | return $objects; |
||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Loads all of the objects of this class by the specified attribute into an array which is returned. |
||
| 400 | * |
||
| 401 | * @param string $attribute The attribute to load the objects by. |
||
| 402 | * @param string $value The value of the attribute to load the objects by. |
||
| 403 | * @param int $start The start of the SQL LIMIT clause, useful for pagination. |
||
| 404 | * @param int $limit The amount (limit) of objects to load, useful for pagination. |
||
| 405 | * @param string $orderBy The name of the field to sort the objects by. |
||
| 406 | * @param string $order The order to sort the objects by. |
||
| 407 | * @param bool $ignoreClassType Default is false, set to true if you want to load from overloaded tables and ignore the class type. |
||
| 408 | * @param array $constructorArgs An optional array of contructor arguements to pass to the records that will be generated and returned. Supports a maximum of 5 arguements. |
||
| 409 | * |
||
| 410 | * @return array An array containing objects of this type of business object. |
||
| 411 | * |
||
| 412 | * @since 1.0 |
||
| 413 | * |
||
| 414 | * @throws \Alpha\Exception\RecordNotFoundException |
||
| 415 | * @throws \Alpha\Exception\IllegalArguementException |
||
| 416 | */ |
||
| 417 | public function loadAllByAttribute($attribute, $value, $start = 0, $limit = 0, $orderBy = 'ID', $order = 'ASC', $ignoreClassType = false, $constructorArgs = array()) |
||
| 418 | { |
||
| 419 | self::$logger->debug('>>loadAllByAttribute(attribute=['.$attribute.'], value=['.$value.'], start=['.$start.'], limit=['.$limit.'], orderBy=['.$orderBy.'], order=['.$order.'], ignoreClassType=['.$ignoreClassType.'], constructorArgs=['.print_r($constructorArgs, true).']'); |
||
| 420 | |||
| 421 | if (method_exists($this, 'before_loadAllByAttribute_callback')) { |
||
| 422 | $this->{'before_loadAllByAttribute_callback'}(); |
||
| 423 | } |
||
| 424 | |||
| 425 | $config = ConfigProvider::getInstance(); |
||
| 426 | |||
| 427 | $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); |
||
| 428 | $provider->setRecord($this); |
||
| 429 | $objects = $provider->loadAllByAttribute($attribute, $value, $start, $limit, $orderBy, $order, $ignoreClassType); |
||
| 430 | |||
| 431 | if (method_exists($this, 'after_loadAllByAttribute_callback')) { |
||
| 432 | $this->{'after_loadAllByAttribute_callback'}(); |
||
| 433 | } |
||
| 434 | |||
| 435 | self::$logger->debug('<<loadAllByAttribute ['.count($objects).']'); |
||
| 436 | |||
| 437 | return $objects; |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Loads all of the objects of this class by the specified attributes into an array which is returned. |
||
| 442 | * |
||
| 443 | * @param array $attributes The attributes to load the objects by. |
||
| 444 | * @param array $values The values of the attributes to load the objects by. |
||
| 445 | * @param int $start The start of the SQL LIMIT clause, useful for pagination. |
||
| 446 | * @param int $limit The amount (limit) of objects to load, useful for pagination. |
||
| 447 | * @param string $orderBy The name of the field to sort the objects by. |
||
| 448 | * @param string $order The order to sort the objects by. |
||
| 449 | * @param bool $ignoreClassType Default is false, set to true if you want to load from overloaded tables and ignore the class type |
||
| 450 | * |
||
| 451 | * @return array An array containing objects of this type of business object. |
||
| 452 | * |
||
| 453 | * @since 1.0 |
||
| 454 | * |
||
| 455 | * @throws \Alpha\Exception\RecordNotFoundException |
||
| 456 | * @throws \Alpha\Exception\IllegalArguementException |
||
| 457 | */ |
||
| 458 | public function loadAllByAttributes($attributes = array(), $values = array(), $start = 0, $limit = 0, $orderBy = 'ID', $order = 'ASC', $ignoreClassType = false) |
||
| 459 | { |
||
| 460 | self::$logger->debug('>>loadAllByAttributes(attributes=['.var_export($attributes, true).'], values=['.var_export($values, true).'], start=['. |
||
| 461 | $start.'], limit=['.$limit.'], orderBy=['.$orderBy.'], order=['.$order.'], ignoreClassType=['.$ignoreClassType.']'); |
||
| 462 | |||
| 463 | if (method_exists($this, 'before_loadAllByAttributes_callback')) { |
||
| 464 | $this->{'before_loadAllByAttributes_callback'}(); |
||
| 465 | } |
||
| 466 | |||
| 467 | $config = ConfigProvider::getInstance(); |
||
| 468 | |||
| 469 | if (!is_array($attributes) || !is_array($values)) { |
||
| 470 | throw new IllegalArguementException('Illegal arrays attributes=['.var_export($attributes, true).'] and values=['.var_export($values, true). |
||
| 471 | '] provided to loadAllByAttributes'); |
||
| 472 | } |
||
| 473 | |||
| 474 | $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); |
||
| 475 | $provider->setRecord($this); |
||
| 476 | $objects = $provider->loadAllByAttributes($attributes, $values, $start, $limit, $orderBy, $order, $ignoreClassType); |
||
| 477 | |||
| 478 | if (method_exists($this, 'after_loadAllByAttributes_callback')) { |
||
| 479 | $this->{'after_loadAllByAttributes_callback'}(); |
||
| 480 | } |
||
| 481 | |||
| 482 | self::$logger->debug('<<loadAllByAttributes ['.count($objects).']'); |
||
| 483 | |||
| 484 | return $objects; |
||
| 485 | } |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Loads all of the objects of this class that where updated (updated_ts value) on the date indicated. |
||
| 489 | * |
||
| 490 | * @param string $date The date for which to load the objects updated on, in the format 'YYYY-MM-DD'. |
||
| 491 | * @param int $start The start of the SQL LIMIT clause, useful for pagination. |
||
| 492 | * @param int $limit The amount (limit) of objects to load, useful for pagination. |
||
| 493 | * @param string $orderBy The name of the field to sort the objects by. |
||
| 494 | * @param string $order The order to sort the objects by. |
||
| 495 | * @param bool $ignoreClassType Default is false, set to true if you want to load from overloaded tables and ignore the class type |
||
| 496 | * |
||
| 497 | * @return array An array containing objects of this type of business object. |
||
| 498 | * |
||
| 499 | * @since 1.0 |
||
| 500 | * |
||
| 501 | * @throws \Alpha\Exception\RecordNotFoundException |
||
| 502 | */ |
||
| 503 | public function loadAllByDayUpdated($date, $start = 0, $limit = 0, $orderBy = 'ID', $order = 'ASC', $ignoreClassType = false) |
||
| 504 | { |
||
| 505 | self::$logger->debug('>>loadAllByDayUpdated(date=['.$date.'], start=['.$start.'], limit=['.$limit.'], orderBy=['.$orderBy.'], order=['.$order.'], ignoreClassType=['.$ignoreClassType.']'); |
||
| 506 | |||
| 507 | if (method_exists($this, 'before_loadAllByDayUpdated_callback')) { |
||
| 508 | $this->{'before_loadAllByDayUpdated_callback'}(); |
||
| 509 | } |
||
| 510 | |||
| 511 | $config = ConfigProvider::getInstance(); |
||
| 512 | |||
| 513 | $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); |
||
| 514 | $provider->setRecord($this); |
||
| 515 | $objects = $provider->loadAllByDayUpdated($date, $start, $limit, $orderBy, $order, $ignoreClassType); |
||
| 516 | |||
| 517 | if (method_exists($this, 'after_loadAllByDayUpdated_callback')) { |
||
| 518 | $this->{'after_loadAllByDayUpdated_callback'}(); |
||
| 519 | } |
||
| 520 | |||
| 521 | self::$logger->debug('<<loadAllByDayUpdated ['.count($objects).']'); |
||
| 522 | |||
| 523 | return $objects; |
||
| 524 | } |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Loads all of the specified attribute values of this class by the specified attribute into an |
||
| 528 | * array which is returned. |
||
| 529 | * |
||
| 530 | * @param string $attribute The attribute name to load the field values by. |
||
| 531 | * @param string $value The value of the attribute to load the field values by. |
||
| 532 | * @param string $returnAttribute The name of the attribute to return. |
||
| 533 | * @param string $order The order to sort the records by. |
||
| 534 | * @param bool $ignoreClassType Default is false, set to true if you want to load from overloaded tables and ignore the class type. |
||
| 535 | * |
||
| 536 | * @return array An array of field values. |
||
| 537 | * |
||
| 538 | * @since 1.0 |
||
| 539 | * |
||
| 540 | * @throws \Alpha\Exception\RecordNotFoundException |
||
| 541 | */ |
||
| 542 | public function loadAllFieldValuesByAttribute($attribute, $value, $returnAttribute, $order = 'ASC', $ignoreClassType = false) |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Saves the object. If $this->ID is empty or null it will INSERT, otherwise UPDATE. |
||
| 559 | * |
||
| 560 | * @since 1.0 |
||
| 561 | * |
||
| 562 | * @throws \Alpha\Exception\FailedSaveException |
||
| 563 | * @throws \Alpha\Exception\LockingException |
||
| 564 | * @throws \Alpha\Exception\ValidationException |
||
| 565 | */ |
||
| 566 | public function save() |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Saves relationship values, including lookup entries, for this record. |
||
| 609 | * |
||
| 610 | * @since 3.0 |
||
| 611 | * |
||
| 612 | * @throws \Alpha\Exception\FailedSaveException |
||
| 613 | */ |
||
| 614 | public function saveRelations() |
||
| 680 | |||
| 681 | /** |
||
| 682 | * Saves the field specified with the value supplied. Only works for persistent records. Note that no Alpha type |
||
| 683 | * validation is performed with this method! |
||
| 684 | * |
||
| 685 | * @param string $attribute The name of the attribute to save. |
||
| 686 | * @param mixed $value The value of the attribute to save. |
||
| 687 | * |
||
| 688 | * @since 1.0 |
||
| 689 | * |
||
| 690 | * @throws \Alpha\Exception\IllegalArguementException |
||
| 691 | * @throws \Alpha\Exception\FailedSaveException |
||
| 692 | */ |
||
| 693 | public function saveAttribute($attribute, $value) |
||
| 726 | |||
| 727 | /** |
||
| 728 | * Saves the history of the object in the [tablename]_history table. It will always perform an insert. |
||
| 729 | * |
||
| 730 | * @since 1.2 |
||
| 731 | * |
||
| 732 | * @throws \Alpha\Exception\FailedSaveException |
||
| 733 | */ |
||
| 734 | public function saveHistory() |
||
| 752 | |||
| 753 | /** |
||
| 754 | * Validates the object to be saved. |
||
| 755 | * |
||
| 756 | * @since 1.0 |
||
| 757 | * |
||
| 758 | * @throws \Alpha\Exception\ValidationException |
||
| 759 | */ |
||
| 760 | protected function validate() |
||
| 795 | |||
| 796 | /** |
||
| 797 | * Deletes the current object from the database. |
||
| 798 | * |
||
| 799 | * @since 1.0 |
||
| 800 | * |
||
| 801 | * @throws \Alpha\Exception\FailedDeleteException |
||
| 802 | */ |
||
| 803 | public function delete() |
||
| 887 | |||
| 888 | /** |
||
| 889 | * Delete all object instances from the database by the specified attribute matching the value provided. |
||
| 890 | * |
||
| 891 | * @param string $attribute The name of the field to delete the objects by. |
||
| 892 | * @param mixed $value The value of the field to delete the objects by. |
||
| 893 | * |
||
| 894 | * @return int The number of rows deleted. |
||
| 895 | * |
||
| 896 | * @since 1.0 |
||
| 897 | * |
||
| 898 | * @throws \Alpha\Exception\FailedDeleteException |
||
| 899 | */ |
||
| 900 | public function deleteAllByAttribute($attribute, $value) |
||
| 934 | |||
| 935 | /** |
||
| 936 | * Gets the version_num of the object from the database (returns 0 if the Record is not saved yet). |
||
| 937 | * |
||
| 938 | * @return int |
||
| 939 | * |
||
| 940 | * @since 1.0 |
||
| 941 | * |
||
| 942 | * @throws \Alpha\Exception\RecordNotFoundException |
||
| 943 | */ |
||
| 944 | public function getVersion() |
||
| 966 | |||
| 967 | /** |
||
| 968 | * Builds a new database table for the Record class. |
||
| 969 | * |
||
| 970 | * @since 1.0 |
||
| 971 | * |
||
| 972 | * @throws \Alpha\Exception\AlphaException |
||
| 973 | */ |
||
| 974 | public function makeTable($checkIndexes = true) |
||
| 996 | |||
| 997 | /** |
||
| 998 | * Builds a new database table for the Record class to story it's history of changes. |
||
| 999 | * |
||
| 1000 | * @since 1.2 |
||
| 1001 | * |
||
| 1002 | * @throws \Alpha\Exception\AlphaException |
||
| 1003 | */ |
||
| 1004 | public function makeHistoryTable() |
||
| 1026 | |||
| 1027 | /** |
||
| 1028 | * Re-builds the table if the model requirements have changed. All data is lost! |
||
| 1029 | * |
||
| 1030 | * @since 1.0 |
||
| 1031 | * |
||
| 1032 | * @throws \Alpha\Exception\AlphaException |
||
| 1033 | */ |
||
| 1034 | public function rebuildTable() |
||
| 1054 | |||
| 1055 | /** |
||
| 1056 | * Drops the table if the model requirements have changed. All data is lost! |
||
| 1057 | * |
||
| 1058 | * @since 1.0 |
||
| 1059 | * |
||
| 1060 | * @param string $tableName Optional table name, leave blank for the defined table for this class to be dropped |
||
| 1061 | * |
||
| 1062 | * @throws \Alpha\Exception\AlphaException |
||
| 1063 | */ |
||
| 1064 | public function dropTable($tableName = null) |
||
| 1084 | |||
| 1085 | /** |
||
| 1086 | * Adds in a new class property without loosing existing data (does an ALTER TABLE query on the |
||
| 1087 | * database). |
||
| 1088 | * |
||
| 1089 | * @param string $propName The name of the new field to add to the database table. |
||
| 1090 | * |
||
| 1091 | * @since 1.0 |
||
| 1092 | * |
||
| 1093 | * @throws \Alpha\Exception\AlphaException |
||
| 1094 | */ |
||
| 1095 | public function addProperty($propName) |
||
| 1115 | |||
| 1116 | /** |
||
| 1117 | * Populates the current business object from the provided hash array. |
||
| 1118 | * |
||
| 1119 | * @param array $hashArray |
||
| 1120 | * |
||
| 1121 | * @since 1.2.1 |
||
| 1122 | */ |
||
| 1123 | public function populateFromArray($hashArray) |
||
| 1159 | |||
| 1160 | /** |
||
| 1161 | * Gets the maximum ID value from the database for this class type. |
||
| 1162 | * |
||
| 1163 | * @return int The maximum ID value in the class table. |
||
| 1164 | * |
||
| 1165 | * @since 1.0 |
||
| 1166 | * |
||
| 1167 | * @throws \Alpha\Exception\AlphaException |
||
| 1168 | */ |
||
| 1169 | public function getMAX() |
||
| 1191 | |||
| 1192 | /** |
||
| 1193 | * Gets the count from the database for the amount of objects of this class. |
||
| 1194 | * |
||
| 1195 | * @param array $attributes The attributes to count the objects by (optional). |
||
| 1196 | * @param array $values The values of the attributes to count the objects by (optional). |
||
| 1197 | * |
||
| 1198 | * @return int |
||
| 1199 | * |
||
| 1200 | * @since 1.0 |
||
| 1201 | * |
||
| 1202 | * @throws \Alpha\Exception\AlphaException |
||
| 1203 | * @throws \Alpha\Exception\IllegalArguementException |
||
| 1204 | */ |
||
| 1205 | public function getCount($attributes = array(), $values = array()) |
||
| 1231 | |||
| 1232 | /** |
||
| 1233 | * Gets the count from the database for the amount of entries in the [tableName]_history table for this business object. Only call |
||
| 1234 | * this method on classes where maintainHistory = true, otherwise an exception will be thrown. |
||
| 1235 | * |
||
| 1236 | * @return int |
||
| 1237 | * |
||
| 1238 | * @since 1.2 |
||
| 1239 | * |
||
| 1240 | * @throws \Alpha\Exception\AlphaException |
||
| 1241 | */ |
||
| 1242 | public function getHistoryCount() |
||
| 1264 | |||
| 1265 | /** |
||
| 1266 | * Gets the ID for the object in zero-padded format (same as getID()). |
||
| 1267 | * |
||
| 1268 | * @return string 11 digit zero-padded ID value. |
||
| 1269 | * |
||
| 1270 | * @since 1.0 |
||
| 1271 | */ |
||
| 1272 | final public function getID() |
||
| 1283 | |||
| 1284 | /** |
||
| 1285 | * Method for getting version number of the object. |
||
| 1286 | * |
||
| 1287 | * @return \Alpha\Model\Type\Integer The object version number. |
||
| 1288 | * |
||
| 1289 | * @since 1.0 |
||
| 1290 | */ |
||
| 1291 | public function getVersionNumber() |
||
| 1298 | |||
| 1299 | /** |
||
| 1300 | * Populate all of the enum options for this object from the database. |
||
| 1301 | * |
||
| 1302 | * @since 1.0 |
||
| 1303 | * |
||
| 1304 | * @throws \Alpha\Exception\AlphaException |
||
| 1305 | */ |
||
| 1306 | protected function setEnumOptions() |
||
| 1326 | |||
| 1327 | /** |
||
| 1328 | * Generic getter method for accessing class properties. Will use the method get.ucfirst($prop) instead if that |
||
| 1329 | * method exists at a child level (by default). Set $noChildMethods to true if you don't want to use any |
||
| 1330 | * get.ucfirst($prop) method even if it exists, false otherwise (default). |
||
| 1331 | * |
||
| 1332 | * @param string $prop The name of the object property to get. |
||
| 1333 | * @param bool $noChildMethods Set to true if you do not want to use getters in the child object, defaults to false. |
||
| 1334 | * |
||
| 1335 | * @return mixed The property value. |
||
| 1336 | * |
||
| 1337 | * @since 1.0 |
||
| 1338 | * |
||
| 1339 | * @throws \Alpha\Exception\IllegalArguementException |
||
| 1340 | * @throws \Alpha\Exception\AlphaException |
||
| 1341 | */ |
||
| 1342 | public function get($prop, $noChildMethods = false) |
||
| 1395 | |||
| 1396 | /** |
||
| 1397 | * Generic setter method for setting class properties. Will use the method set.ucfirst($prop) instead if that |
||
| 1398 | * method exists at a child level (by default). Set $noChildMethods to true if you don't want to use |
||
| 1399 | * any get.ucfirst($prop) method even if it exists, false otherwise (default). |
||
| 1400 | * |
||
| 1401 | * @param string $prop The name of the property to set. |
||
| 1402 | * @param mixed $value The value of the property to set. |
||
| 1403 | * @param bool $noChildMethods Set to true if you do not want to use setters in the child object, defaults to false. |
||
| 1404 | * |
||
| 1405 | * @since 1.0 |
||
| 1406 | * |
||
| 1407 | * @throws \Alpha\Exception\AlphaException |
||
| 1408 | */ |
||
| 1409 | public function set($prop, $value, $noChildMethods = false) |
||
| 1451 | |||
| 1452 | /** |
||
| 1453 | * Gets the property object rather than the value for complex attributes. Returns false if |
||
| 1454 | * the property exists but is private. |
||
| 1455 | * |
||
| 1456 | * @param string $prop The name of the property we are getting. |
||
| 1457 | * |
||
| 1458 | * @return \Alpha\Model\Type\Type|bool The complex type object found. |
||
| 1459 | * |
||
| 1460 | * @since 1.0 |
||
| 1461 | * |
||
| 1462 | * @throws \Alpha\Exception\IllegalArguementException |
||
| 1463 | */ |
||
| 1464 | public function getPropObject($prop) |
||
| 1506 | |||
| 1507 | /** |
||
| 1508 | * Checks to see if the table exists in the database for the current business class. |
||
| 1509 | * |
||
| 1510 | * @param bool $checkHistoryTable Set to true if you want to check for the existance of the _history table for this DAO. |
||
| 1511 | * |
||
| 1512 | * @return bool |
||
| 1513 | * |
||
| 1514 | * @since 1.0 |
||
| 1515 | * |
||
| 1516 | * @throws \Alpha\Exception\AlphaException |
||
| 1517 | */ |
||
| 1518 | public function checkTableExists($checkHistoryTable = false) |
||
| 1540 | |||
| 1541 | /** |
||
| 1542 | * Static method to check the database and see if the table for the indicated Record class name |
||
| 1543 | * exists (assumes table name will be $recordClassName less "Object"). |
||
| 1544 | * |
||
| 1545 | * @param string $recordClassName The name of the business object class we are checking. |
||
| 1546 | * @param bool $checkHistoryTable Set to true if you want to check for the existance of the _history table for this DAO. |
||
| 1547 | * |
||
| 1548 | * @return bool |
||
| 1549 | * |
||
| 1550 | * @since 1.0 |
||
| 1551 | * |
||
| 1552 | * @throws \Alpha\Exception\AlphaException |
||
| 1553 | */ |
||
| 1554 | public static function checkRecordTableExists($recordClassName, $checkHistoryTable = false) |
||
| 1571 | |||
| 1572 | /** |
||
| 1573 | * Checks to see if the table in the database matches (for fields) the business class definition, i.e. if the |
||
| 1574 | * database table is in sync with the class definition. |
||
| 1575 | * |
||
| 1576 | * @return bool |
||
| 1577 | * |
||
| 1578 | * @since 1.0 |
||
| 1579 | * |
||
| 1580 | * @throws \Alpha\Exception\AlphaException |
||
| 1581 | */ |
||
| 1582 | public function checkTableNeedsUpdate() |
||
| 1612 | |||
| 1613 | /** |
||
| 1614 | * Returns an array containing any properties on the class which have not been created on the database |
||
| 1615 | * table yet. |
||
| 1616 | * |
||
| 1617 | * @return array An array of missing fields in the database table. |
||
| 1618 | * |
||
| 1619 | * @since 1.0 |
||
| 1620 | * |
||
| 1621 | * @throws \Alpha\Exception\AlphaException |
||
| 1622 | */ |
||
| 1623 | public function findMissingFields() |
||
| 1645 | |||
| 1646 | /** |
||
| 1647 | * Getter for the TABLE_NAME, which should be set by a child of this class. |
||
| 1648 | * |
||
| 1649 | * @return string The table name in the database. |
||
| 1650 | * |
||
| 1651 | * @since 1.0 |
||
| 1652 | * |
||
| 1653 | * @throws \Alpha\Exception\AlphaException |
||
| 1654 | */ |
||
| 1655 | public function getTableName() |
||
| 1671 | |||
| 1672 | /** |
||
| 1673 | * Method for getting the ID of the person who created this record. |
||
| 1674 | * |
||
| 1675 | * @return \Alpha\Model\Type\Integer The ID of the creator. |
||
| 1676 | * |
||
| 1677 | * @since 1.0 |
||
| 1678 | */ |
||
| 1679 | public function getCreatorId() |
||
| 1686 | |||
| 1687 | /** |
||
| 1688 | * Method for getting the ID of the person who updated this record. |
||
| 1689 | * |
||
| 1690 | * @return \Alpha\Model\Type\Integer The ID of the updator. |
||
| 1691 | * |
||
| 1692 | * @since 1.0 |
||
| 1693 | */ |
||
| 1694 | public function getUpdatorId() |
||
| 1701 | |||
| 1702 | /** |
||
| 1703 | * Method for getting the date/time of when the Record was created. |
||
| 1704 | * |
||
| 1705 | * @return \Alpha\Model\Type\Timestamp |
||
| 1706 | * |
||
| 1707 | * @since 1.0 |
||
| 1708 | */ |
||
| 1709 | public function getCreateTS() |
||
| 1716 | |||
| 1717 | /** |
||
| 1718 | * Method for getting the date/time of when the Record was last updated. |
||
| 1719 | * |
||
| 1720 | * @return \Alpha\Model\Type\Timestamp |
||
| 1721 | * |
||
| 1722 | * @since 1.0 |
||
| 1723 | */ |
||
| 1724 | public function getUpdateTS() |
||
| 1731 | |||
| 1732 | /** |
||
| 1733 | * Adds the name of the attribute provided to the list of transient (non-saved) attributes for this record. |
||
| 1734 | * |
||
| 1735 | * @param string $attributeName The name of the attribute to not save. |
||
| 1736 | * |
||
| 1737 | * @since 1.0 |
||
| 1738 | */ |
||
| 1739 | public function markTransient($attributeName) |
||
| 1745 | |||
| 1746 | /** |
||
| 1747 | * Removes the name of the attribute provided from the list of transient (non-saved) attributes for this record, |
||
| 1748 | * ensuring that it will be saved on the next attempt. |
||
| 1749 | * |
||
| 1750 | * @param string $attributeName The name of the attribute to save. |
||
| 1751 | * |
||
| 1752 | * @since 1.0 |
||
| 1753 | */ |
||
| 1754 | public function markPersistent($attributeName) |
||
| 1760 | |||
| 1761 | /** |
||
| 1762 | * Adds the name of the attribute(s) provided to the list of unique (constrained) attributes for this record. |
||
| 1763 | * |
||
| 1764 | * @param string $attribute1Name The first attribute to mark unique in the database. |
||
| 1765 | * @param string $attribute2Name The second attribute to mark unique in the databse (optional, use only for composite keys). |
||
| 1766 | * @param string $attribute3Name The third attribute to mark unique in the databse (optional, use only for composite keys). |
||
| 1767 | * |
||
| 1768 | * @since 1.0 |
||
| 1769 | */ |
||
| 1770 | protected function markUnique($attribute1Name, $attribute2Name = '', $attribute3Name = '') |
||
| 1789 | |||
| 1790 | /** |
||
| 1791 | * Returns the array of names of unique attributes on this record. |
||
| 1792 | * |
||
| 1793 | * @return array |
||
| 1794 | * |
||
| 1795 | * @since 1.1 |
||
| 1796 | */ |
||
| 1797 | public function getUniqueAttributes() |
||
| 1804 | |||
| 1805 | /** |
||
| 1806 | * Gets an array of all of the names of the active database indexes for this class. |
||
| 1807 | * |
||
| 1808 | * @return array An array of database indexes on this table. |
||
| 1809 | * |
||
| 1810 | * @since 1.0 |
||
| 1811 | * |
||
| 1812 | * @throws \Alpha\Exception\AlphaException |
||
| 1813 | */ |
||
| 1814 | public function getIndexes() |
||
| 1828 | |||
| 1829 | /** |
||
| 1830 | * Creates a foreign key constraint (index) in the database on the given attribute. |
||
| 1831 | * |
||
| 1832 | * @param string $attributeName The name of the attribute to apply the index on. |
||
| 1833 | * @param string $relatedClass The name of the related class in the format "NameObject". |
||
| 1834 | * @param string $relatedClassAttribute The name of the field to relate to on the related class. |
||
| 1835 | * @param string $indexName The optional name for the index, will calculate if not provided. |
||
| 1836 | * |
||
| 1837 | * @since 1.0 |
||
| 1838 | * |
||
| 1839 | * @throws \Alpha\Exception\FailedIndexCreateException |
||
| 1840 | */ |
||
| 1841 | public function createForeignIndex($attributeName, $relatedClass, $relatedClassAttribute, $indexName = null) |
||
| 1871 | |||
| 1872 | /** |
||
| 1873 | * Creates a unique index in the database on the given attribute(s). |
||
| 1874 | * |
||
| 1875 | * @param string $attribute1Name The first attribute to mark unique in the database. |
||
| 1876 | * @param string $attribute2Name The second attribute to mark unique in the databse (optional, use only for composite keys). |
||
| 1877 | * @param string $attribute3Name The third attribute to mark unique in the databse (optional, use only for composite keys). |
||
| 1878 | * |
||
| 1879 | * @since 1.0 |
||
| 1880 | * |
||
| 1881 | * @throws \Alpha\Exception\FailedIndexCreateException |
||
| 1882 | */ |
||
| 1883 | public function createUniqueIndex($attribute1Name, $attribute2Name = '', $attribute3Name = '') |
||
| 1903 | |||
| 1904 | /** |
||
| 1905 | * Gets the data labels array. |
||
| 1906 | * |
||
| 1907 | * @return array An array of attribute labels. |
||
| 1908 | * |
||
| 1909 | * @since 1.0 |
||
| 1910 | */ |
||
| 1911 | public function getDataLabels() |
||
| 1918 | |||
| 1919 | /** |
||
| 1920 | * Sets the data labels array. |
||
| 1921 | * |
||
| 1922 | * @param array $labels |
||
| 1923 | * |
||
| 1924 | * @throws \Alpha\Exception\IllegalArguementException |
||
| 1925 | * |
||
| 1926 | * @since 1.2 |
||
| 1927 | */ |
||
| 1928 | public function setDataLabels($labels) |
||
| 1940 | |||
| 1941 | /** |
||
| 1942 | * Gets the data label for the given attribute name. |
||
| 1943 | * |
||
| 1944 | * @param $att The attribute name to get the label for. |
||
| 1945 | * |
||
| 1946 | * @return string |
||
| 1947 | * |
||
| 1948 | * @since 1.0 |
||
| 1949 | * |
||
| 1950 | * @throws \Alpha\Exception\IllegalArguementException |
||
| 1951 | */ |
||
| 1952 | public function getDataLabel($att) |
||
| 1965 | |||
| 1966 | /** |
||
| 1967 | * Loops over the core and custom Record directories and builds an array of all of the Record class names in the system. |
||
| 1968 | * |
||
| 1969 | * @return array An array of business object class names. |
||
| 1970 | * |
||
| 1971 | * @since 1.0 |
||
| 1972 | */ |
||
| 1973 | public static function getRecordClassNames() |
||
| 2023 | |||
| 2024 | /** |
||
| 2025 | * Get the array of default attribute names. |
||
| 2026 | * |
||
| 2027 | * @return array An array of attribute names. |
||
| 2028 | * |
||
| 2029 | * @since 1.0 |
||
| 2030 | */ |
||
| 2031 | public function getDefaultAttributes() |
||
| 2038 | |||
| 2039 | /** |
||
| 2040 | * Get the array of transient attribute names. |
||
| 2041 | * |
||
| 2042 | * @return array An array of attribute names. |
||
| 2043 | * |
||
| 2044 | * @since 1.0 |
||
| 2045 | */ |
||
| 2046 | public function getTransientAttributes() |
||
| 2053 | |||
| 2054 | /** |
||
| 2055 | * Get the array of persistent attribute names, i.e. those that are saved in the database. |
||
| 2056 | * |
||
| 2057 | * @return array An array of attribute names. |
||
| 2058 | * |
||
| 2059 | * @since 1.0 |
||
| 2060 | */ |
||
| 2061 | public function getPersistentAttributes() |
||
| 2084 | |||
| 2085 | /** |
||
| 2086 | * Setter for the Object ID (ID). |
||
| 2087 | * |
||
| 2088 | * @param int $ID The Object ID. |
||
| 2089 | * |
||
| 2090 | * @since 1.0 |
||
| 2091 | */ |
||
| 2092 | public function setID($ID) |
||
| 2098 | |||
| 2099 | /** |
||
| 2100 | * Inspector to see if the business object is transient (not presently stored in the database). |
||
| 2101 | * |
||
| 2102 | * @return bool |
||
| 2103 | * |
||
| 2104 | * @since 1.0 |
||
| 2105 | */ |
||
| 2106 | public function isTransient() |
||
| 2120 | |||
| 2121 | /** |
||
| 2122 | * Get the last database query run on this object. |
||
| 2123 | * |
||
| 2124 | * @return string An SQL query string. |
||
| 2125 | * |
||
| 2126 | * @since 1.0 |
||
| 2127 | */ |
||
| 2128 | public function getLastQuery() |
||
| 2135 | |||
| 2136 | /** |
||
| 2137 | * Unsets all of the attributes of this object to null. |
||
| 2138 | * |
||
| 2139 | * @since 1.0 |
||
| 2140 | */ |
||
| 2141 | private function clear() |
||
| 2158 | |||
| 2159 | /** |
||
| 2160 | * Reloads the object from the database, overwritting any attribute values in memory. |
||
| 2161 | * |
||
| 2162 | * @since 1.0 |
||
| 2163 | * |
||
| 2164 | * @throws \Alpha\Exception\AlphaException |
||
| 2165 | */ |
||
| 2166 | public function reload() |
||
| 2177 | |||
| 2178 | /** |
||
| 2179 | * Checks that a record exists for the Record in the database. |
||
| 2180 | * |
||
| 2181 | * @param int $ID The Object ID of the object we want to see whether it exists or not. |
||
| 2182 | * |
||
| 2183 | * @return bool |
||
| 2184 | * |
||
| 2185 | * @since 1.0 |
||
| 2186 | * |
||
| 2187 | * @throws \Alpha\Exception\AlphaException |
||
| 2188 | */ |
||
| 2189 | public function checkRecordExists($ID) |
||
| 2211 | |||
| 2212 | /** |
||
| 2213 | * Checks to see if the table name matches the classname, and if not if the table |
||
| 2214 | * name matches the classname name of another record, i.e. the table is used to store |
||
| 2215 | * multiple types of records. |
||
| 2216 | * |
||
| 2217 | * @return bool |
||
| 2218 | * |
||
| 2219 | * @since 1.0 |
||
| 2220 | * |
||
| 2221 | * @throws \Alpha\Exception\BadTableNameException |
||
| 2222 | */ |
||
| 2223 | public function isTableOverloaded() |
||
| 2237 | |||
| 2238 | /** |
||
| 2239 | * Starts a new database transaction. |
||
| 2240 | * |
||
| 2241 | * @param ActiveRecord $record The ActiveRecord instance to pass to the database provider. Leave empty to have a new Person passed. |
||
| 2242 | * |
||
| 2243 | * @since 1.0 |
||
| 2244 | * |
||
| 2245 | * @throws \Alpha\Exception\AlphaException |
||
| 2246 | */ |
||
| 2247 | public static function begin($record = null) |
||
| 2272 | |||
| 2273 | /** |
||
| 2274 | * Commits the current database transaction. |
||
| 2275 | * |
||
| 2276 | * @param ActiveRecord $record The ActiveRecord instance to pass to the database provider. Leave empty to have a new Person passed. |
||
| 2277 | * |
||
| 2278 | * @since 1.0 |
||
| 2279 | * |
||
| 2280 | * @throws \Alpha\Exception\FailedSaveException |
||
| 2281 | */ |
||
| 2282 | public static function commit($record = null) |
||
| 2307 | |||
| 2308 | /** |
||
| 2309 | * Aborts the current database transaction. |
||
| 2310 | * |
||
| 2311 | * @param ActiveRecord $record The ActiveRecord instance to pass to the database provider. Leave empty to have a new Person passed. |
||
| 2312 | * |
||
| 2313 | * @since 1.0 |
||
| 2314 | * |
||
| 2315 | * @throws \Alpha\Exception\AlphaException |
||
| 2316 | */ |
||
| 2317 | public static function rollback($record = null) |
||
| 2342 | |||
| 2343 | /** |
||
| 2344 | * Static method that tries to determine if the system database has been installed or not. |
||
| 2345 | * |
||
| 2346 | * @return bool |
||
| 2347 | * |
||
| 2348 | * @since 1.0 |
||
| 2349 | */ |
||
| 2350 | public static function isInstalled() |
||
| 2373 | |||
| 2374 | /** |
||
| 2375 | * Returns true if the Record has a Relation property called tags, false otherwise. |
||
| 2376 | * |
||
| 2377 | * @return bool |
||
| 2378 | * |
||
| 2379 | * @since 1.0 |
||
| 2380 | */ |
||
| 2381 | public function isTagged() |
||
| 2389 | |||
| 2390 | /** |
||
| 2391 | * Returns the contents of the taggedAttributes array, or an empty array if that does not exist. |
||
| 2392 | * |
||
| 2393 | * @return array |
||
| 2394 | * |
||
| 2395 | * @since 1.2.3 |
||
| 2396 | */ |
||
| 2397 | public function getTaggedAttributes() |
||
| 2405 | |||
| 2406 | /** |
||
| 2407 | * Setter for the Record version number. |
||
| 2408 | * |
||
| 2409 | * @param int $versionNumber The version number. |
||
| 2410 | * |
||
| 2411 | * @since 1.0 |
||
| 2412 | */ |
||
| 2413 | private function setVersion($versionNumber) |
||
| 2417 | |||
| 2418 | /** |
||
| 2419 | * Cast a Record to another type of record. A new Record will be returned with the same ID and |
||
| 2420 | * version_num as the old record, so this is NOT a true cast but is a copy. All attribute |
||
| 2421 | * values will be copied accross. |
||
| 2422 | * |
||
| 2423 | * @param string $targetClassName The fully-qualified name of the target Record class. |
||
| 2424 | * @param \Alpha\Model\ActiveRecord $originalRecord The original business object. |
||
| 2425 | * |
||
| 2426 | * @return \Alpha\Model\ActiveRecord The new business object resulting from the cast. |
||
| 2427 | * |
||
| 2428 | * @since 1.0 |
||
| 2429 | */ |
||
| 2430 | public function cast($targetClassName, $originalRecord) |
||
| 2464 | |||
| 2465 | /** |
||
| 2466 | * Returns the simple class name, stripped of the namespace. |
||
| 2467 | * |
||
| 2468 | * @return string |
||
| 2469 | * |
||
| 2470 | * @since 1.0 |
||
| 2471 | */ |
||
| 2472 | public function getFriendlyClassName() |
||
| 2478 | |||
| 2479 | /** |
||
| 2480 | * Check to see if an attribute exists on the record. |
||
| 2481 | * |
||
| 2482 | * @param string $attribute The attribute name. |
||
| 2483 | * |
||
| 2484 | * @return bool |
||
| 2485 | * |
||
| 2486 | * @since 1.0 |
||
| 2487 | */ |
||
| 2488 | public function hasAttribute($attribute) |
||
| 2492 | |||
| 2493 | /** |
||
| 2494 | * Stores the business object to the configured cache instance. |
||
| 2495 | * |
||
| 2496 | * @since 1.1 |
||
| 2497 | */ |
||
| 2498 | public function addToCache() |
||
| 2513 | |||
| 2514 | /** |
||
| 2515 | * Removes the business object from the configured cache instance. |
||
| 2516 | * |
||
| 2517 | * @since 1.1 |
||
| 2518 | */ |
||
| 2519 | public function removeFromCache() |
||
| 2534 | |||
| 2535 | /** |
||
| 2536 | * Attempts to load the business object from the configured cache instance. |
||
| 2537 | * |
||
| 2538 | * @since 1.1 |
||
| 2539 | * |
||
| 2540 | * @return bool |
||
| 2541 | */ |
||
| 2542 | public function loadFromCache() |
||
| 2590 | |||
| 2591 | /** |
||
| 2592 | * Sets the last query executed on this business object. |
||
| 2593 | * |
||
| 2594 | * @param string $query |
||
| 2595 | * |
||
| 2596 | * @since 1.1 |
||
| 2597 | */ |
||
| 2598 | public function setLastQuery($query) |
||
| 2603 | |||
| 2604 | /** |
||
| 2605 | * Re-initialize the static logger property on the Record after de-serialize, as PHP does |
||
| 2606 | * not serialize static properties. |
||
| 2607 | * |
||
| 2608 | * @since 1.2 |
||
| 2609 | */ |
||
| 2610 | public function __wakeup() |
||
| 2616 | |||
| 2617 | /** |
||
| 2618 | * Sets maintainHistory attribute on this DAO. |
||
| 2619 | * |
||
| 2620 | * @param bool $maintainHistory |
||
| 2621 | * |
||
| 2622 | * @throws \Alpha\Exception\IllegalArguementException |
||
| 2623 | * |
||
| 2624 | * @since 1.2 |
||
| 2625 | */ |
||
| 2626 | public function setMaintainHistory($maintainHistory) |
||
| 2634 | |||
| 2635 | /** |
||
| 2636 | * Gets the value of the maintainHistory attribute. |
||
| 2637 | * |
||
| 2638 | * @return bool |
||
| 2639 | * |
||
| 2640 | * @since 1.2 |
||
| 2641 | */ |
||
| 2642 | public function getMaintainHistory() |
||
| 2646 | |||
| 2647 | /** |
||
| 2648 | * Return a hash array of the object containing attribute names and simplfied values. |
||
| 2649 | * |
||
| 2650 | * @return array |
||
| 2651 | * |
||
| 2652 | * @since 1.2.4 |
||
| 2653 | */ |
||
| 2654 | public function toArray() |
||
| 2678 | |||
| 2679 | /** |
||
| 2680 | * Check to see if the configured database exists. |
||
| 2681 | * |
||
| 2682 | * @return bool |
||
| 2683 | * |
||
| 2684 | * @since 2.0 |
||
| 2685 | */ |
||
| 2686 | public static function checkDatabaseExists() |
||
| 2695 | |||
| 2696 | /** |
||
| 2697 | * Creates the configured database. |
||
| 2698 | * |
||
| 2699 | * @throws \Alpha\Exception\AlphaException |
||
| 2700 | * |
||
| 2701 | * @since 2.0 |
||
| 2702 | */ |
||
| 2703 | public static function createDatabase() |
||
| 2711 | |||
| 2712 | /** |
||
| 2713 | * Drops the configured database. |
||
| 2714 | * |
||
| 2715 | * @throws \Alpha\Exception\AlphaException |
||
| 2716 | * |
||
| 2717 | * @since 2.0 |
||
| 2718 | */ |
||
| 2719 | public static function dropDatabase() |
||
| 2727 | |||
| 2728 | /** |
||
| 2729 | * Backup the configured database. |
||
| 2730 | * |
||
| 2731 | * @param string $targetFile The file that the backup data will be written to. |
||
| 2732 | * |
||
| 2733 | * @throws \Alpha\Exception\AlphaException |
||
| 2734 | * |
||
| 2735 | * @since 3.0 |
||
| 2736 | */ |
||
| 2737 | public static function backupDatabase($targetFile) |
||
| 2745 | } |
||
| 2746 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: