[EXCEPTION] Make findOne return NotFoundException
This commit is contained in:
parent
c07a0cdcd5
commit
63d2d58e9e
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// {{{ License
|
// {{{ License
|
||||||
|
|
||||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
//
|
//
|
||||||
// GNU social is free software: you can redistribute it and/or modify
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
|
@ -15,6 +16,7 @@
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,13 +32,13 @@
|
||||||
|
|
||||||
namespace App\Core\DB;
|
namespace App\Core\DB;
|
||||||
|
|
||||||
|
use App\Util\Exception\NotFoundException;
|
||||||
use App\Util\Formatting;
|
use App\Util\Formatting;
|
||||||
use Doctrine\Common\Collections\Criteria;
|
use Doctrine\Common\Collections\Criteria;
|
||||||
use Doctrine\Common\Collections\ExpressionBuilder;
|
use Doctrine\Common\Collections\ExpressionBuilder;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||||
use Exception;
|
|
||||||
|
|
||||||
abstract class DB
|
abstract class DB
|
||||||
{
|
{
|
||||||
|
@ -117,7 +119,7 @@ abstract class DB
|
||||||
if (count($res) == 1) {
|
if (count($res) == 1) {
|
||||||
return $res[0];
|
return $res[0];
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("No value in table {$table} matches the requested criteria");
|
throw new NotFoundException("No value in table {$table} matches the requested criteria");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
30
src/Util/Exception/NotFoundException.php
Normal file
30
src/Util/Exception/NotFoundException.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// {{{ License
|
||||||
|
|
||||||
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
|
//
|
||||||
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// GNU social is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
namespace App\Util\Exception;
|
||||||
|
|
||||||
|
class NotFoundException extends ServerException
|
||||||
|
{
|
||||||
|
public function __construct(string $m)
|
||||||
|
{
|
||||||
|
parent::__construct($m);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user