Skip to content

Commit

Permalink
[#14213] - Added enum class for the dispatcher constants
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Jul 4, 2019
1 parent 82abff2 commit 4a574e0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Phalcon\Dispatcher;
use Exception;
use Phalcon\DiInterface;
use Phalcon\Di\InjectionAwareInterface;
use Phalcon\Dispatcher\Enum;
use Phalcon\Dispatcher\DispatcherInterface;
use Phalcon\Events\EventsAwareInterface;
use Phalcon\Events\ManagerInterface;
Expand All @@ -28,13 +29,6 @@ use Phalcon\Mvc\Model\BinderInterface;
*/
abstract class AbstractDispatcher implements DispatcherInterface, InjectionAwareInterface, EventsAwareInterface
{
const EXCEPTION_ACTION_NOT_FOUND = 5;
const EXCEPTION_CYCLIC_ROUTING = 1;
const EXCEPTION_HANDLER_NOT_FOUND = 2;
const EXCEPTION_INVALID_HANDLER = 3;
const EXCEPTION_INVALID_PARAMS = 4;
const EXCEPTION_NO_DI = 0;

protected activeHandler;

/**
Expand Down Expand Up @@ -145,7 +139,7 @@ abstract class AbstractDispatcher implements DispatcherInterface, InjectionAware
PhalconException::containerServiceNotFound(
"related dispatching services"
),
self::EXCEPTION_NO_DI
Enum::EXCEPTION_NO_DI
);

return false;
Expand Down Expand Up @@ -208,7 +202,7 @@ abstract class AbstractDispatcher implements DispatcherInterface, InjectionAware
if unlikely numberDispatches == 256 {
this->{"throwDispatchException"}(
"Dispatcher has detected a cyclic routing causing stability problems",
self::EXCEPTION_CYCLIC_ROUTING
Enum::EXCEPTION_CYCLIC_ROUTING
);

break;
Expand Down Expand Up @@ -253,7 +247,7 @@ abstract class AbstractDispatcher implements DispatcherInterface, InjectionAware
if !hasService {
let status = this->{"throwDispatchException"}(
handlerClass . " handler class cannot be loaded",
self::EXCEPTION_HANDLER_NOT_FOUND
Enum::EXCEPTION_HANDLER_NOT_FOUND
);

if status === false && this->finished === false {
Expand All @@ -269,7 +263,7 @@ abstract class AbstractDispatcher implements DispatcherInterface, InjectionAware
if unlikely typeof handler !== "object" {
let status = this->{"throwDispatchException"}(
"Invalid handler returned from the services container",
self::EXCEPTION_INVALID_HANDLER
Enum::EXCEPTION_INVALID_HANDLER
);

if status === false && this->finished === false {
Expand Down Expand Up @@ -304,7 +298,7 @@ abstract class AbstractDispatcher implements DispatcherInterface, InjectionAware
*/
let status = this->{"throwDispatchException"}(
"Action parameters must be an Array",
self::EXCEPTION_INVALID_PARAMS
Enum::EXCEPTION_INVALID_PARAMS
);

if status === false && this->finished === false {
Expand Down Expand Up @@ -334,7 +328,7 @@ abstract class AbstractDispatcher implements DispatcherInterface, InjectionAware
*/
let status = this->{"throwDispatchException"}(
"Action '" . actionName . "' was not found on handler '" . handlerName . "'",
self::EXCEPTION_ACTION_NOT_FOUND
Enum::EXCEPTION_ACTION_NOT_FOUND
);

if status === false && this->finished === false {
Expand Down Expand Up @@ -808,7 +802,7 @@ abstract class AbstractDispatcher implements DispatcherInterface, InjectionAware
PhalconException::containerServiceNotFound(
"the 'filter' service"
),
self::EXCEPTION_NO_DI
Enum::EXCEPTION_NO_DI
);
}

Expand Down
24 changes: 24 additions & 0 deletions phalcon/Dispatcher/Enum.zep
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Dispatcher;

/**
* Constants for the Dispatcher
*/
class Enum
{
const EXCEPTION_ACTION_NOT_FOUND = 5;
const EXCEPTION_CYCLIC_ROUTING = 1;
const EXCEPTION_HANDLER_NOT_FOUND = 2;
const EXCEPTION_INVALID_HANDLER = 3;
const EXCEPTION_INVALID_PARAMS = 4;
const EXCEPTION_NO_DI = 0;
}

0 comments on commit 4a574e0

Please sign in to comment.