mirror of
https://github.com/webmasterskaya/joomla-oauth-server.git
synced 2024-11-23 22:34:50 +03:00
Rollback to native Joomla behavior without throws
This commit is contained in:
parent
eb2de74d13
commit
bdd62cac3c
@ -12,53 +12,50 @@ namespace Webmasterskaya\Component\OauthServer\Administrator\Model;
|
|||||||
use Joomla\CMS\Language\Text;
|
use Joomla\CMS\Language\Text;
|
||||||
use Joomla\CMS\Object\CMSObject;
|
use Joomla\CMS\Object\CMSObject;
|
||||||
use Joomla\CMS\Table\Table;
|
use Joomla\CMS\Table\Table;
|
||||||
|
use Joomla\Registry\Registry;
|
||||||
use Joomla\Utilities\ArrayHelper;
|
use Joomla\Utilities\ArrayHelper;
|
||||||
|
|
||||||
\defined('_JEXEC') or die;
|
\defined('_JEXEC') or die;
|
||||||
|
|
||||||
trait GetItemByIdentifierTrait
|
trait GetItemByIdentifierTrait
|
||||||
{
|
{
|
||||||
public function getItemByIdentifier($identifier = null): object
|
/**
|
||||||
|
* @param $identifier
|
||||||
|
*
|
||||||
|
* @return object|bool
|
||||||
|
* @throws \Exception
|
||||||
|
* @since version
|
||||||
|
*/
|
||||||
|
public function getItemByIdentifier($identifier): object|bool
|
||||||
{
|
{
|
||||||
$identifier = (!empty($identifier)) ? $identifier : (int) $this->getState($this->getName() . '.identifier');
|
|
||||||
/** @var Table $table */
|
/** @var Table $table */
|
||||||
$table = $this->getTable();
|
$table = $this->getTable();
|
||||||
|
|
||||||
if (!empty($identifier))
|
|
||||||
{
|
|
||||||
$return = $table->load(['identifier' => $identifier]);
|
$return = $table->load(['identifier' => $identifier]);
|
||||||
|
|
||||||
if ($return === false)
|
if ($return === false)
|
||||||
{
|
{
|
||||||
if (method_exists($table, 'getError') && $table->getError())
|
// If there was no underlying error, then the false means there simply was not a row in the db for this $pk.
|
||||||
{
|
if (!$table->getError()) {
|
||||||
throw new \RuntimeException($table->getError());
|
$this->setError(Text::_('JLIB_APPLICATION_ERROR_NOT_EXIST'));
|
||||||
}
|
} else {
|
||||||
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_NOT_EXIST'));
|
$this->setError($table->getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to the CMSObject before adding other data.
|
// Convert to the CMSObject before adding other data.
|
||||||
$properties = $table->getProperties(true);
|
$properties = $table->getProperties(1);
|
||||||
$all_properties = $table->getProperties(false);
|
$item = ArrayHelper::toObject($properties, CMSObject::class);
|
||||||
|
|
||||||
if (!empty($all_properties['_jsonEncode']))
|
if (property_exists($item, 'params')) {
|
||||||
{
|
$registry = new Registry($item->params);
|
||||||
foreach ($all_properties['_jsonEncode'] as $prop)
|
$item->params = $registry->toArray();
|
||||||
{
|
|
||||||
if (array_key_exists($prop, $properties) && is_string($properties[$prop]))
|
|
||||||
{
|
|
||||||
$properties[$prop] = json_decode($properties[$prop]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ArrayHelper::toObject($properties, CMSObject::class, true);
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public function getState($property = null, $default = null);
|
|
||||||
|
|
||||||
abstract public function getName();
|
|
||||||
|
|
||||||
abstract public function getTable($name = '', $prefix = '', $options = []);
|
abstract public function getTable($name = '', $prefix = '', $options = []);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user