mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-13 12:14:06 +02:00
[ticket/12683] Improve exception handling
PHPBB3-12683
This commit is contained in:
@@ -82,7 +82,7 @@ class list_all extends command
|
||||
foreach ($this->search_backend_collection as $search_backend)
|
||||
{
|
||||
$name = $search_backend->get_type();
|
||||
$active = ($name === $this->config['search_type']) ? '(<comment>' . $this->language->lang('$') . '</comment>) ' : '';
|
||||
$active = ($name === $this->config['search_type']) ? '(<comment>' . $this->language->lang('ACTIVE') . '</comment>) ' : '';
|
||||
$search_backends[] = '<info>' . $name . '</info> ' . $active . $search_backend->get_name();
|
||||
|
||||
if ($name === $this->config['search_type'] && !$search_backend->index_created())
|
||||
|
@@ -15,6 +15,7 @@ namespace phpbb\cron\task\core;
|
||||
|
||||
use phpbb\config\config;
|
||||
use phpbb\cron\task\base;
|
||||
use phpbb\di\exception\di_exception;
|
||||
use phpbb\search\backend\search_backend_interface;
|
||||
use phpbb\search\search_backend_factory;
|
||||
|
||||
@@ -88,7 +89,7 @@ class tidy_search extends base
|
||||
$this->active_search = $this->search_backend_factory->get_active();
|
||||
}
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
catch (di_exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
21
phpBB/phpbb/di/exception/di_exception.php
Normal file
21
phpBB/phpbb/di/exception/di_exception.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||
*
|
||||
* For full copyright and license information, please see
|
||||
* the docs/CREDITS.txt file.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace phpbb\di\exception;
|
||||
|
||||
use phpbb\exception\runtime_exception;
|
||||
|
||||
class di_exception extends runtime_exception
|
||||
{
|
||||
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace phpbb\di\exception;
|
||||
|
||||
class multiple_service_definitions_exception extends di_exception
|
||||
{
|
||||
|
||||
}
|
8
phpBB/phpbb/di/exception/service_not_found_exception.php
Normal file
8
phpBB/phpbb/di/exception/service_not_found_exception.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace phpbb\di\exception;
|
||||
|
||||
class service_not_found_exception extends di_exception
|
||||
{
|
||||
|
||||
}
|
@@ -13,6 +13,8 @@
|
||||
|
||||
namespace phpbb\di;
|
||||
|
||||
use phpbb\di\exception\multiple_service_definitions_exception;
|
||||
use phpbb\di\exception\service_not_found_exception;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
@@ -105,7 +107,7 @@ class service_collection extends \ArrayObject
|
||||
{
|
||||
if ($service_id !== null)
|
||||
{
|
||||
throw new \RuntimeException('More than one service definitions found for class "'.$class.'" in collection.');
|
||||
throw new multiple_service_definitions_exception('DI_MULTIPLE_SERVICE_DEFINITIONS', [$class]);
|
||||
}
|
||||
|
||||
$service_id = $id;
|
||||
@@ -114,7 +116,7 @@ class service_collection extends \ArrayObject
|
||||
|
||||
if ($service_id === null)
|
||||
{
|
||||
throw new \RuntimeException('No service found for class "'.$class.'" in collection.');
|
||||
throw new service_not_found_exception('DI_SERVICE_NOT_FOUND', [$class]);
|
||||
}
|
||||
|
||||
return $this->offsetGet($service_id);
|
||||
|
@@ -14,10 +14,10 @@
|
||||
namespace phpbb\search;
|
||||
|
||||
use phpbb\config\config;
|
||||
use phpbb\di\exception\service_not_found_exception;
|
||||
use phpbb\di\service_collection;
|
||||
use phpbb\search\backend\search_backend_interface;
|
||||
use phpbb\search\exception\no_search_backend_found_exception;
|
||||
use RuntimeException;
|
||||
|
||||
class search_backend_factory
|
||||
{
|
||||
@@ -58,16 +58,9 @@ class search_backend_factory
|
||||
{
|
||||
$search = $this->search_backends->get_by_class($class);
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
catch (service_not_found_exception $e)
|
||||
{
|
||||
if (strpos($e->getMessage(), 'No service found') === 0)
|
||||
{
|
||||
throw new no_search_backend_found_exception();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw $e;
|
||||
}
|
||||
throw new no_search_backend_found_exception('SEARCH_BACKEND_NOT_FOUND', [], $e);
|
||||
}
|
||||
|
||||
return $search;
|
||||
|
@@ -113,7 +113,7 @@ class state_helper
|
||||
// Make sure the action is correct (just in case)
|
||||
if (!in_array($action, ['create', 'delete']))
|
||||
{
|
||||
throw new search_exception('Invalid action');
|
||||
throw new search_exception('INVALID_ACTION');
|
||||
}
|
||||
|
||||
$state = [
|
||||
|
Reference in New Issue
Block a user