Skip to content

Commit

Permalink
Implement websocket and add helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
kekefreedog committed Jan 12, 2025
1 parent 9183f16 commit b4311b0
Showing 19 changed files with 1,097 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ package-lock.json

# Etc
.DS_Store
bin/*.pid
bin/*.log

# PHPUnit (PHP)
.phpunit.result.cache
29 changes: 29 additions & 0 deletions bin/CrazyWebsocket
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env php
<?php
/**
* Crazy Migration
*
* Command for controle migration
*
* PHP version 8.1.2
*
* @package kzarshenas/crazyphp
* @author kekefreedog <kevin.zarshenas@gmail.com>
* @copyright 2022-2024 Kévin Zarshenas
*/
require getcwd().'/vendor/autoload.php' ;

/**
* Dependances
*/
use CrazyPHP\Model\Env;
use CrazyPHP\Cli\Core;

# Define env constants
Env::set([
"app_root" => getcwd(),
"crazyphp_root" => getcwd()."/vendor/kzarshenas/crazyphp",
]);

// Execute core
(new Core())->run();
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -28,10 +28,11 @@
"nyholm/psr7-server": "^1.0",
"laminas/laminas-httphandlerrunner": "^2.3",
"psr/http-message": "^1.0",
"cboden/ratchet": "^0.4.4",
"phpmyadmin/sql-parser": "^5.9",
"vlucas/phpdotenv": "^5.6",
"ozdemirburak/iris": "^3.1"
"ozdemirburak/iris": "^3.1",
"workerman/workerman": "^5.0",
"pelago/emogrifier": "^7.3"
},
"require-dev": {
"phpunit/phpunit": "^11"
@@ -41,4 +42,4 @@
"php -f ./vendor/phpunit/phpunit/phpunit"
]
}
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
"filepond-plugin-image-preview": "^4.6.12",
"imask": "^7.6.1",
"killa": "^1.9.1",
"reconnecting-websocket": "^4.4.0",
"tom-select": "^2.3.1"
}
}
}
45 changes: 45 additions & 0 deletions resources/Js/Handlebars/dateToLocalFormat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Handlebars Strings Helpers
*
* @source https://github.com/helpers/handlebars-helpers
*
* @package kzarshenas/crazyphp
* @author kekefreedog <kevin.zarshenas@gmail.com>
* @copyright 2022-2024 Kévin Zarshenas
*/

/**
* Date To Local Format
*
* Return date to local format Vendredi 13 Janvier
*
* @param input
* @param local ()
*
* @return string
*/
module.exports = function(input, locale, options) {

// Set result
let result = input;

// Check input
if(typeof input === "string" && input && typeof locale === "string" && locale){

// convert to date
const date = new Date(input);

// Invalid date fallback
if(!isNaN(date)){

// Set options
const options = { weekday: 'long', day: 'numeric', month: 'long' };

// Set result
result = date.toLocaleDateString(locale, options);

}

}

};
60 changes: 60 additions & 0 deletions resources/Js/Handlebars/daysOfMonth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Handlebars Array Helpers
*
* @source https://github.com/helpers/handlebars-helpers
*
* @package kzarshenas/crazyphp
* @author kekefreedog <kevin.zarshenas@gmail.com>
* @copyright 2022-2024 Kévin Zarshenas
*/

/**
* Days of month
*
* Handlebars helper to get all days of a given month and year
*
* @param {number} year - The year (e.g., 2025).
* @param {number} month - The month (1 for January, 12 for December).
* @param {object} options - Handlebars options object.
* @returns {string} - Rendered HTML of all dates.
*/
module.exports = function(year, month, options) {

// Check year
year = Number.isInteger(year) && year > 0
? year
: now.getFullYear()
;

// Check month
month = Number.isInteger(month) && month >= 1 && month <= 12
? month
: now.getMonth() + 1
;

// Adjust for JavaScript's 0-based months
const adjustedMonth = month - 1;

// Get number of days in the month
const daysInMonth = new Date(year, month, 0).getDate();

// Get days
const days = [];

// Iteration days in month
for(let day = 1; day <= daysInMonth; day++){

// Set date
const date = new Date(year, adjustedMonth, day);

// Set formated date
const formattedDate = date.toISOString().split('T')[0];

// Push in result
days.push(formattedDate);
}

// Return days
return days;

}
27 changes: 27 additions & 0 deletions resources/Js/Handlebars/isCurrentDay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Handlebars Comparaison Helpers
*
* @source https://github.com/helpers/handlebars-helpers
*
* @package kzarshenas/crazyphp
* @author kekefreedog <kevin.zarshenas@gmail.com>
* @copyright 2022-2024 Kévin Zarshenas
*/

/**
* Is Current Day
*
* Returns true if value (2025-01-05) is the current day
*
* @param input like 2025-01-12
* @return boolean
*/
module.exports = function(input, options) {

// Return result
return typeof input === "string" && input && inputDate === (new Date().toISOString().split('T')[0])
? options.fn(this)
: options.inverse(this)
;

};
47 changes: 47 additions & 0 deletions resources/Js/Handlebars/isWeekend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Handlebars Comparaison Helpers
*
* @source https://github.com/helpers/handlebars-helpers
*
* @package kzarshenas/crazyphp
* @author kekefreedog <kevin.zarshenas@gmail.com>
* @copyright 2022-2024 Kévin Zarshenas
*/

/**
* Is Weekend
*
* Returns true if value (2025-01-05) is the weekend
*
* @param input like 2025-01-12
* @return boolean
*/
module.exports = function(input, options) {

// Set result
let result = false;

// Check date
if(typeof input === "string" && input){

// Set date
const date = new Date(inputDate);

// Get day in week 0 = Sunday, 6 = Saturday
const day = date.getDay();

// Check if weekend
if(day === 0 || day === 6)

// Set result
result = true;

}

// Return result
return result
? options.fn(this)
: options.inverse(this)
;

};
Loading

0 comments on commit b4311b0

Please sign in to comment.