2013-07-21 09:27:00 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorDataNotAttachedException extends Exception {
|
|
|
|
|
2014-08-13 14:41:06 -07:00
|
|
|
public function __construct($object) {
|
2013-07-21 09:27:00 -07:00
|
|
|
$stack = debug_backtrace();
|
|
|
|
|
|
|
|
// Shift off `PhabricatorDataNotAttachedException::__construct()`.
|
|
|
|
array_shift($stack);
|
|
|
|
// Shift off `PhabricatorLiskDAO::assertAttached()`.
|
|
|
|
array_shift($stack);
|
|
|
|
|
|
|
|
$frame = head($stack);
|
|
|
|
$via = null;
|
|
|
|
if (is_array($frame)) {
|
|
|
|
$method = idx($frame, 'function');
|
|
|
|
if (preg_match('/^get[A-Z]/', $method)) {
|
2015-05-22 17:27:56 +10:00
|
|
|
$via = ' '.pht('(via %s)', "{$method}()");
|
2013-07-21 09:27:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-22 17:27:56 +10:00
|
|
|
parent::__construct(
|
|
|
|
pht(
|
|
|
|
"Attempting to access attached data on %s, but the data is not ".
|
|
|
|
"actually attached. Before accessing attachable data on an object, ".
|
|
|
|
"you must load and attach it.\n\n".
|
|
|
|
"Data is normally attached by calling the corresponding %s method on ".
|
|
|
|
"the Query class when the object is loaded. You can also call the ".
|
|
|
|
"corresponding %s method explicitly.",
|
|
|
|
get_class($object).$via,
|
|
|
|
'needX()',
|
|
|
|
'attachX()'));
|
2013-07-21 09:27:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|