PHP Classes

File: Rules-For-Route-Configuration.md

Recommend this page to a friend!
  Packages of Ramesh Narayan Jangid (Sharma)   Open Swoole Microservices   Rules-For-Route-Configuration.md   Download  
File: Rules-For-Route-Configuration.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: Open Swoole Microservices
Implement microservices using Open Swoole
Author: By
Last change:
Date: 6 hours ago
Size: 3,626 bytes
 

Contents

Class file image Download

Route Configuration Rules

Available configuration syntax explained

  • For configuring route /tableName/parts GET method
    return [
    'tableName' => [
    	'parts' => [
    		'__FILE__' => 'SQL file location'
    	]
    ]
    ];
    
  • For configuring route /tableName/{id} where id is dynamic integer value to be collected.
    return [
    'tableName' => [
    	'{id:int}' => [
    		'dataType' => DatabaseServerDataType::$PrimaryKey,
    		'__FILE__' => 'SQL file location'
    	]
    ]
    ];
    
  • Same dynamic variable but with a different data type, for e.g. {id} will be treated differently for string and integer values to be collected.
return [
	'tableName' => [
		'{id:int}' => [
			'dataType' => DatabaseServerDataType::$PrimaryKey,
			'__FILE__' => 'SQL file location for integer data type'
		],
		'{id:string}' => [
			'dataType' => DatabaseServerDataType::$Default,
			'__FILE__' => 'SQL file location for string data type'
		]
	]
];

  • To restrict dynamic values to a certain set of values. One can do the same by defining its data type.
return [
	'{tableName:string}' => [
		'dataType' => DatabaseServerDataType::$Tables,
		'{id:int}' => [
			'__FILE__' => 'SQL file location'
		]
	]
];

Hook

return [
	'{tableName:string}' => [
		'dataType' => DatabaseServerDataType::$Tables,
		'__FILE__' => 'SQL file location',
		'__PRE-ROUTE-HOOKS__' => [// These will apply recursively
			'Hook_1',
			'...'
		],
		'__POST-ROUTE-HOOKS__' => [// These will apply recursively
			'Hook_1',
			'...'
		]
		'{id:int}' => [
			'dataType' => DatabaseServerDataType::$PrimaryKey,
			'__FILE__' => 'SQL file location',
			'__PRE-ROUTE-HOOKS__' => [], // For noi hooks
			'__POST-ROUTE-HOOKS__' => [] // For noi hooks
		],

		// Input Data Representation
		'iRepresentation' => 'XML' // JSON/XML - Defaults to JSON
	]
];

  • This '{id:int|!0}' means id is integer but can't be zero.

Defining Custom DataTypes

public static $PrimaryKey = [

// Required param
	// PHP data type (bool, int, float, string)
	'dataType' => 'int',

// Optional params
	// Value can be null
	'canBeNull' => false,
	// Minimum value (int)
	'minValue' => 1,
	// Maximum value (int)
	'maxValue' => false,
	// Minimum length (string)
	'minLength' => false,
	// Maximum length (string)
	'maxLength' => false,
	// Any one value from the Array
	'enumValues' => false,
	// Values belonging to this Array
	'setValues' => false,

	// Values should pass this regex before use
	'regex' => false
];

Special Route

  • Appending route with /explain returns the payload information that should be supplied; both required and optional with desired format.

Examples:

  • route=/registration/explain (returns the payload information)
  • route=/registration/import (import CSV)
  • route=/registration/import-sample (sample CSV download for respective HTTP Method)

One need to enable same in .env file as below

; Keyword to append with in route with slash.
; Explain Route & its Payload
explainRequestRouteKeyword='explain'    ; to append "/explain" at the end of route
importRequestRouteKeyword='import'  ; to append "/import" at the end of route
importSampleRequestRouteKeyword='import-sample'

Contributing

Issues and feature request are welcome.<br /> Feel free to share them on issues page

Author

  • Ramesh N. Jangid (Sharma)

Github: @polygoncoin

License

Copyright © 2026 Ramesh N. Jangid (Sharma).<br /> This project is MIT licensed.