Skip to content

Commit

Permalink
Fix mango issue + update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
kekefreedog committed Jan 13, 2024
1 parent 6378dfb commit d25bd7a
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 83 deletions.
5 changes: 3 additions & 2 deletions docs/Docker/Php.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Php with Docker

## USe shell command
## Use shell command

For use shell command of php server, use bellow shell command
```sh

```sh {"id":"01HKSG0MQA06WJTW4V1ZQ588DK"}
docker exec -it crazytest-php-fpm-1 bash
```

69 changes: 69 additions & 0 deletions src/Front/Library/Utility/Objects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Utility
*
* Front TS Scrips for multiple tasks
*
* @package kzarshenas/crazyphp
* @author kekefreedog <[email protected]>
* @copyright 2022-2023 Kévin Zarshenas
*/

/**
* Dependances
*/

/**
* Arrays
*
* Methods for manage arrays
*
* @package kzarshenas/crazyphp
* @author kekefreedog <[email protected]>
* @copyright 2022-2023 Kévin Zarshenas
*/
export default class Objects {

/** Public static methods
******************************************************
*/

/**
* Array Filter
*
* @param obj Input object
* @param separator Separator to nested (default ".")
* @return any
*/
public static convertToNestedObject = (obj:Object, separator:string = '.'):any => {

// Declare result
const result = {};

// Iteration obj
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
if (key.includes(separator)) {
const keys = key.split(separator);
let current = result;

for (let i = 0; i < keys.length; i++) {
if (i === keys.length - 1) {
current[keys[i]] = obj[key];
} else {
current[keys[i]] = current[keys[i]] || {};
current = current[keys[i]];
}
}
} else if (typeof obj[key] === 'object' && obj[key] !== null) {
result[key] = this.convertToNestedObject(obj[key], separator);
} else {
result[key] = obj[key];
}
}
}

// Return result
return result;
}

}
1 change: 1 addition & 0 deletions src/Front/Types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export {default as Componentregister} from "./../Library/Componentregister";
export {default as NavigatorClient} from "./../Library/Navigator/Client";
export {default as ColorSchema} from "./../Library/Utility/ColorSchema";
export {default as UtilityProcess} from "./../Library/Utility/Process";
export {default as UtilityObjects} from "./../Library/Utility/Objects";
export {default as Crazycomponent} from "./../Library/Crazycomponent";
export {default as Crazynavigator} from "./../Library/Crazynavigator";
export {default as UtilityArrays} from "./../Library/Utility/Arrays";
Expand Down
1 change: 1 addition & 0 deletions src/Front/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export {default as Componentregister} from "./Library/Componentregister";
export {default as NavigatorClient} from "./Library/Navigator/Client";
export {default as ColorSchema} from "./Library/Utility/ColorSchema";
export {default as UtilityProcess} from "./Library/Utility/Process";
export {default as UtilityObjects} from "./Library/Utility/Objects";
export {default as Crazycomponent} from "./Library/Crazycomponent";
export {default as Crazynavigator} from "./Library/Crazynavigator";
export {default as UtilityEvents} from "./Library/Utility/Events";
Expand Down
87 changes: 6 additions & 81 deletions src/Library/Database/Driver/Mangodb.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,86 +777,6 @@ public static function convertToMongoSchema(array $schema = []):array {
# Return result
return $result;

/* # Check schema
if(empty($schema))
# Return result
return $result;
# Declare properties
$properties = [];
# Declare required
$required = [];
# Iteration schema
foreach($schema as $attribute){
# Get type
$type = $attribute['type'];
# Convert SQL data types to BSON data types
switch($type){
# Case varchar
case 'VARCHAR':
# Set bson type
$bsonType = 'string';
# Break
break;
# Set default
default:
# Set bson type
$bsonType = 'string';
}
# Fill properties
$properties[$attribute['name']] = [
'bsonType' => $bsonType,
'description' => ($attribute['label'] ?? $attribute['name'])." must be a \”$bsonType\”"
];
# Check required
if($attribute["required"] ?? false)
# Fill required
$required[] = $attribute['name'];
}
# Check properties and required
if(!empty($properties) || !empty($required)){
# Prepare result
$result = [
'validator' => [
'$jsonSchema' => [
'bsonType' => 'object'
]
]
];
# Check properties
if(!empty($properties))
$result["validator"]['$jsonSchema']["properties"] = $properties;
# Check properties
if(!empty($required))
# Check required
$result["validator"]['$jsonSchema']["required"] = $required;
}
# Return result
return $result; */

}

/** Public Static Methods
Expand Down Expand Up @@ -941,7 +861,12 @@ private static function _recursiveMongoSchemaConvertor(array $schema = [], strin
$description = null;

# Recursive
$recursiveResult = static::_recursiveMongoSchemaConvertor($schema, $name);
$recursiveResult = static::_recursiveMongoSchemaConvertor(
$schema,
$prefix
? "$prefix.$name"
: $name
);

# Set bson type
$bsonType = $recursiveResult["bsonType"] ?? "object";
Expand Down
57 changes: 57 additions & 0 deletions tests/Library/Database/MongodbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ class MongodbTest extends TestCase {
],
];

/** @const array SCHEMA */
public const SCHEMA_BIS = [
[
'name' => 'attributes.sg_department_1.Department.sg_division',
'label' => 'Entity type',
'type' => 'VARCHAR',
# 'required' => true,
],
];

/** @cont array EXPECTED */
public const EXPECTED = [
'validator' => [
Expand Down Expand Up @@ -116,6 +126,36 @@ class MongodbTest extends TestCase {
],
],
];

/** @cont array EXPECTED */
public const EXPECTED_BIS = [
'validator' => [
'$jsonSchema' => [
'bsonType' => 'object',
'properties' => [
'attributes' => [
'bsonType' => 'object',
'properties' => [
'sg_department_1' => [
'bsonType' => 'object',
'properties' => [
'Department' => [
'bsonType' => 'object',
'properties' => [
'sg_division' => [
'bsonType' => 'string',
'description' => 'Entity type must be a "string"',
],
],
],
],
],
],
],
],
],
],
];


/** Public method | Preparation
Expand Down Expand Up @@ -177,4 +217,21 @@ public function testPageState():void {

}

/**
* Test Page State
*
* Test envAndConfigValues function
*
* @return void
*/
public function testPageStateBis():void {

# New schema
$mongoSchema = Mangodb::convertToMongoSchema(static::SCHEMA_BIS);

# Assert
$this->assertEquals(self::EXPECTED_BIS, $mongoSchema);

}

}

0 comments on commit d25bd7a

Please sign in to comment.