Skip to content

Commit

Permalink
Tidied up Router\Annotations::processActionAnnotation().
Browse files Browse the repository at this point in the history
  • Loading branch information
SidRoberts authored and niden committed Jun 10, 2019
1 parent e0d3655 commit 2ec28a4
Showing 1 changed file with 96 additions and 108 deletions.
204 changes: 96 additions & 108 deletions phalcon/Mvc/Router/Annotations.zep
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,18 @@ class Annotations extends Router
let lowerControllerName = uncamelize(controllerName);

for method, collection in methodAnnotations {
if typeof collection == "object" {
for annotation in collection->getAnnotations() {
this->processActionAnnotation(
moduleName,
namespaceName,
lowerControllerName,
method,
annotation
);
}
if typeof collection != "object" {
continue;
}

for annotation in collection->getAnnotations() {
this->processActionAnnotation(
moduleName,
namespaceName,
lowerControllerName,
method,
annotation
);
}
}
}
Expand Down Expand Up @@ -232,136 +234,122 @@ class Annotations extends Router
break;

case "Get":
let isRoute = true, methods = "GET";
break;

case "Post":
let isRoute = true, methods = "POST";
break;

case "Put":
let isRoute = true, methods = "PUT";
break;

case "Patch":
let isRoute = true, methods = "PATCH";
break;

case "Delete":
let isRoute = true, methods = "DELETE";
break;

case "Options":
let isRoute = true, methods = "OPTIONS";
let isRoute = true,
methods = strtoupper(name);
break;
}

if isRoute {
let actionName = strtolower(str_replace(this->actionSuffix, "", action)),
routePrefix = this->routePrefix;
if !isRoute {
return;
}

/**
* Check for existing paths in the annotation
*/
let paths = annotation->getNamedArgument("paths");
let actionName = strtolower(str_replace(this->actionSuffix, "", action)),
routePrefix = this->routePrefix;

if typeof paths != "array" {
let paths = [];
}
/**
* Check for existing paths in the annotation
*/
let paths = annotation->getNamedArgument("paths");

/**
* Update the module if any
*/
if !empty module {
let paths["module"] = module;
}
if typeof paths != "array" {
let paths = [];
}

/**
* Update the namespace if any
*/
if !empty namespaceName {
let paths["namespace"] = namespaceName;
}
/**
* Update the module if any
*/
if !empty module {
let paths["module"] = module;
}

let paths["controller"] = controller,
paths["action"] = actionName;
/**
* Update the namespace if any
*/
if !empty namespaceName {
let paths["namespace"] = namespaceName;
}

let value = annotation->getArgument(0);
let paths["controller"] = controller,
paths["action"] = actionName;

/**
* Create the route using the prefix
*/
if value !== null {
if value != "/" {
let uri = routePrefix . value;
let value = annotation->getArgument(0);

/**
* Create the route using the prefix
*/
if value !== null {
if value != "/" {
let uri = routePrefix . value;
} else {
if routePrefix !== null {
let uri = routePrefix;
} else {
if routePrefix !== null {
let uri = routePrefix;
} else {
let uri = value;
}
let uri = value;
}
} else {
let uri = routePrefix . actionName;
}
} else {
let uri = routePrefix . actionName;
}

/**
* Add the route to the router
*/
let route = this->add(uri, paths);
/**
* Add the route to the router
*/
let route = this->add(uri, paths);

/**
* Add HTTP constraint methods
*/
if methods !== null {
route->via(methods);
} else {
let methods = annotation->getNamedArgument("methods");
/**
* Add HTTP constraint methods
*/
if methods === null {
let methods = annotation->getNamedArgument("methods");
}

if typeof methods == "array" || typeof methods == "string" {
route->via(methods);
}
}
if typeof methods == "array" || typeof methods == "string" {
route->via(methods);
}

/**
* Add the converters
*/
let converts = annotation->getNamedArgument("converts");
/**
* Add the converters
*/
let converts = annotation->getNamedArgument("converts");

if typeof converts == "array" {
for param, convert in converts {
route->convert(param, convert);
}
if typeof converts == "array" {
for param, convert in converts {
route->convert(param, convert);
}
}

/**
* Add the conversors
*/
let converts = annotation->getNamedArgument("conversors");
/**
* Add the conversors
*/
let converts = annotation->getNamedArgument("conversors");

if typeof converts == "array" {
for conversorParam, convert in converts {
route->convert(conversorParam, convert);
}
if typeof converts == "array" {
for conversorParam, convert in converts {
route->convert(conversorParam, convert);
}
}

/**
* Add the conversors
*/
let beforeMatch = annotation->getNamedArgument("beforeMatch");

if typeof beforeMatch == "array" || typeof beforeMatch == "string" {
route->beforeMatch(beforeMatch);
}
/**
* Add the conversors
*/
let beforeMatch = annotation->getNamedArgument("beforeMatch");

let routeName = annotation->getNamedArgument("name");
if typeof beforeMatch == "array" || typeof beforeMatch == "string" {
route->beforeMatch(beforeMatch);
}

if typeof routeName == "string" {
route->setName(routeName);
}
let routeName = annotation->getNamedArgument("name");

return true;
if typeof routeName == "string" {
route->setName(routeName);
}

return true;
}

/**
Expand Down

0 comments on commit 2ec28a4

Please sign in to comment.