Skip to content

Commit

Permalink
Implement CLI router type
Browse files Browse the repository at this point in the history
  • Loading branch information
kekefreedog committed Oct 29, 2023
1 parent 0861612 commit 3071fb3
Show file tree
Hide file tree
Showing 8 changed files with 679 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ Delete router
php vendor/kzarshenas/crazyphp/bin/CrazyCommand delete router
```

## Router Type

New router type

```sh
php vendor/kzarshenas/crazyphp/bin/CrazyCommand new routerType
```

Delete router type

```sh
php vendor/kzarshenas/crazyphp/bin/CrazyCommand delete routerType
```

## Trash

Clean trash
Expand Down Expand Up @@ -90,6 +104,7 @@ php vendor/phpunit/phpunit/phpunit
| CONFIG_LOCATION | @config_location | \<string> | Determine the location of the configs files |
| ROUTER_APP_PATH | @router_app_path | \<string> | Determine the path of the front files of the routers |
| ROUTER_CONTROLLER_PATH | @router_controller_path | \<string> | Determine the path of the back end controller of routers |
| ROUTER_TYPE_PATH | @router_type_path | \<string> | Determine the path of the back end router type |
| TRASH_PATH | @trash_path | \<string> | Determine the path of the trash |
| TRASH_DISABLE | @trash_disable | \<string> | Determine if the trash is disable |

Expand Down
59 changes: 59 additions & 0 deletions resources/Hbs/App/routerType.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php declare(strict_types=1);
/**
* Api
*
* Workflow of your api
*
* PHP version 8.1.2
*
* @package kzarshenas/crazyphp
* @author kekefreedog <kevin[email protected]>
* @copyright 2022-2023 Kévin Zarshenas
*/
namespace {{Namespace}};

/**
* Dependances
*/
use CrazyPHP\Interface\CrazyRouterType;
use CrazyPHP\Core\Router;

/**
* {{Class}}
*
* Class for manage {{Name}} router type
*
* @package kzarshenas/crazyphp
* @author kekefreedog <kevin[email protected]>
* @copyright 2022-2023 Kévin Zarshenas
*/
class {{Class}} implements CrazyRouterType {

/**
* Search Reg Exp
*
* Method returns regexp for searching this entity in the URL
*
* @return string regexp for searching
*/
public static function searchRegExp():string {

# Return
return '(\[{{Name}}:'.Router::PARAMETER_NAME_REGEX.'\])';
}

/**
* Parser Reg Exp
*
* Method returns regexp to parse the language code if it occurs
*
* @return string regexp for parsing
*/
public static function parserRegExp():string {

# Regular expression for ISO 639-1 standard language codes
return '{{Regex}}';

}

}
1 change: 1 addition & 0 deletions resources/Yml/Router.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Router:
parameters:
api:
format: json
type : {}
methods:
- get
- post
Expand Down
10 changes: 10 additions & 0 deletions src/Cli/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,11 @@ private function _checkInRouter(array $inputs = []):void {
"class" => "\CrazyPHP\Model\Router\Create",
"parameter" => "router",
],
# Router
"routerType" => [
"class" => "\CrazyPHP\Model\RouterType\Create",
"parameter" => "router",
],
],
],
# Command delete
Expand All @@ -1539,6 +1544,11 @@ private function _checkInRouter(array $inputs = []):void {
"class" => "\CrazyPHP\Model\Router\Delete",
"parameter" => "routers",
],
# Router
"routerType" => [
"class" => "\CrazyPHP\Model\RouterType\Delete",
"parameter" => "router",
],
# Trash
"trash" => [
"class" => "\CrazyPHP\Model\Trash\Delete",
Expand Down
16 changes: 15 additions & 1 deletion src/Library/Form/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class Process {
"snakeToCamel",
"spaceBeforeCapital",
"ucfirst",
"cleanPath"
"cleanPath",
"strtolower"
],
"ARRAY" => [
],
Expand Down Expand Up @@ -782,6 +783,19 @@ public static function ucfirst(string $input):string {

}

/**
* Lower Case
*
* @param string
* @return string
*/
public static function strtolower(string $input):string {

# Return result
return strtolower($input);

}

/**
* Wash
*
Expand Down
59 changes: 59 additions & 0 deletions src/Library/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ public static function reverse(string $name, ?array $arguments = null):string {
* Get Summary
*
* Get a summary of existing routers
*
* @return array
*/
public static function getSummary():array {
Expand Down Expand Up @@ -620,6 +621,43 @@ public static function getSummary():array {

}

/**
* Get Router Type Summary
*
* Get a summary of existing router type
*
* @return array
*/
public static function getRouterTypeSummary():array {

# Set result
$result = [];

# Get routers
$routerTypeCollection = Config::getValue("Router.type");

# Check routers
if(is_array($routerTypeCollection) && !empty($routerTypeCollection)){

# Iteration routers
foreach($routerTypeCollection as $routerType){

# Check router name
if(isset($routerType["name"]) && $routerType["name"]){

$result[$routerType["name"]] = ucfirst($routerType["name"]);

}

}

}

# Return result
return $result;

}

/** Public static methods | Routers file
******************************************************
*/
Expand Down Expand Up @@ -660,6 +698,24 @@ public static function getControllerPath():string {

}

/**
* Get Router Type Path
*
* Get path of the custom router type
* env : "router_type_path"
*
* @return string
*/
public static function getRouterTypePath():string {

# Set result
$result = Env::get("router_type_path", true) ?: static::ROUTER_TYPE_PATH;

# Return result
return $result;

}

/** Public constants
******************************************************
*/
Expand All @@ -683,4 +739,7 @@ public static function getControllerPath():string {
/** @const public ROUTER_CONTROLLER_PATH */
public const ROUTER_CONTROLLER_PATH = "@app_root/app/Controller/";

/** @const public ROUTER_TYPE_PATH */
public const ROUTER_TYPE_PATH = "@app_root/app/Library/Router/Type/";

}
Loading

0 comments on commit 3071fb3

Please sign in to comment.