@@ -247,12 +247,12 @@ static public function sizeToBytes($size = '1mb')
247247 /**
248248 * Get file modification time
249249 *
250- * @param string $path
250+ * @param string|null $path
251251 *
252252 * @return mixed
253253 * - int|bool
254254 */
255- static public function getFiletime (? string $ path = null )
255+ static public function getFiletime ($ path = null )
256256 {
257257 $ fullPath = self ::getBasePath ($ path );
258258
@@ -540,14 +540,14 @@ static public function sortArray(?array $arry = [], ?string $type = 'sort')
540540 /**
541541 * For sorting muti-dimentional array
542542 *
543- * @param string $key
543+ * @param string|null $key
544544 * @param array $arry
545545 * @param string $type
546546 * - [asc|desc|snum]
547547 *
548548 * @return void
549549 */
550- static public function sortMultipleArray (? string $ key = null , ?array &$ arry = [], ?string $ type = 'asc ' )
550+ static public function sortMultipleArray ($ key = null , ?array &$ arry = [], ?string $ type = 'asc ' )
551551 {
552552 $ id = array_column ($ arry , $ key );
553553 switch ($ type ) {
@@ -568,14 +568,14 @@ static public function sortMultipleArray(?string $key = null, ?array &$arry = []
568568 /**
569569 * Clean phone string
570570 *
571- * @param string $phone
571+ * @param string|null $phone
572572 *
573573 * @param bool $allow --- Default is true
574574 * [optional] to allow `+` before number
575575 *
576576 * @return string
577577 */
578- static public function cleanPhoneNumber (? string $ phone = null , ?bool $ allow = true )
578+ static public function cleanPhoneNumber ($ phone = null , ?bool $ allow = true )
579579 {
580580 $ phone = str_replace (' ' , '' , str_replace ('- ' , '' , $ phone ));
581581 $ phone = str_replace ('( ' , '' , str_replace (') ' , '' , $ phone ));
@@ -593,11 +593,11 @@ static public function cleanPhoneNumber(?string $phone = null, ?bool $allow = tr
593593 /**
594594 * Remove special characters while allowing all languages.
595595 *
596- * @param string $string
596+ * @param string|null $string
597597 * @return string|null
598598 * - The cleaned string or null if the input is empty.
599599 */
600- static public function removeSpecialChars (? string $ string = null )
600+ static public function removeSpecialChars ($ string = null )
601601 {
602602 if (empty ($ string )) {
603603 return null ;
@@ -612,7 +612,7 @@ static public function removeSpecialChars(?string $string = null)
612612 * @param string|null $string The input string to clean.
613613 * @return string The cleaned string.
614614 */
615- static public function cleanTagsForURL (? string $ string = null )
615+ static public function cleanTagsForURL ($ string = null )
616616 {
617617 // Remove unwanted characters from the string
618618 $ string = preg_replace ('/[^\p{L}\p{N}\s]/u ' , '' , (string ) $ string );
@@ -623,13 +623,13 @@ static public function cleanTagsForURL(?string $string = null)
623623 /**
624624 * Hash String
625625 *
626- * @param string $string
626+ * @param string|null $string
627627 * @param int $length
628628 * @param string $type
629629 * @param int $interation
630630 * @return void
631631 */
632- static public function stringHash (? string $ string = null , $ length = 100 , $ type = 'sha256 ' , $ interation = 100 )
632+ static public function stringHash ($ string = null , $ length = 100 , $ type = 'sha256 ' , $ interation = 100 )
633633 {
634634 return hash_pbkdf2 ($ type , mt_rand () . $ string , self ::PBKDF2_SALT , $ interation , $ length );
635635 }
@@ -663,21 +663,21 @@ static public function shortenString($string = null, $limit = 50, $replacer = '.
663663 /**
664664 * Decode entity html strings
665665 *
666- * @param string $string
666+ * @param string|null $string
667667 * @return string
668668 */
669669 static public function html ($ string = null )
670670 {
671- return html_entity_decode ($ string , ENT_HTML5 , 'UTF-8 ' );
671+ return html_entity_decode (( string ) $ string , ENT_HTML5 , 'UTF-8 ' );
672672 }
673673
674674 /**
675675 * Filter sanitize string
676676 *
677- * @param string $string
677+ * @param string|null $string
678678 * @return string
679679 */
680- static public function filter_input (? string $ string = null )
680+ static public function filter_input ($ string = null )
681681 {
682682 return htmlspecialchars ((string ) $ string , ENT_QUOTES | ENT_HTML5 , 'UTF-8 ' );
683683 }
@@ -710,35 +710,17 @@ static public function formatNumberToNearestThousand(float|int $number = 0)
710710
711711 return $ number ;
712712 }
713-
714- /**
715- * Convert json data to array|object
716- *
717- * @param string $path
718- *
719- * @param bool $format
720- * - [optional] Default is true and this converts to an array
721- * false will convert to and object
722- *
723- * @return array
724- */
725- static public function convertJsonData (?string $ path = null , $ format = true )
726- {
727- if (self ::exists ($ path )){
728- return json_decode (file_get_contents ($ path ), $ format );
729- }
730- }
731713
732714 /**
733715 * Unlink File from Server
734716 *
735717 * @param string $fileToUnlink
736- * @param string $checkFile
718+ * @param string|null $checkFile
737719 * [optional] File to check against before unlinking
738720 *
739721 * @return void
740722 */
741- static public function unlinkFile (string $ fileToUnlink , ? string $ checkFile = null )
723+ static public function unlinkFile (string $ fileToUnlink , $ checkFile = null )
742724 {
743725 $ fileToUnlink = self ::getBasePath ($ fileToUnlink );
744726 $ checkFile = self ::getBasePath ($ checkFile );
@@ -749,40 +731,71 @@ static public function unlinkFile(string $fileToUnlink, ?string $checkFile = nul
749731 }
750732 }
751733 }
734+
735+ /**
736+ * Convert json data to array|object
737+ *
738+ * @param string|null $path
739+ *
740+ * @param bool $format
741+ * - [optional] Default is true and this converts to an array
742+ * false will convert to and object
743+ *
744+ * @return array
745+ */
746+ static public function convertJsonData ($ path = null , $ format = true )
747+ {
748+ if (self ::exists ($ path )){
749+ return json_decode (file_get_contents ($ path ), $ format );
750+ }
751+ }
752752
753753 /**
754- * Save Data to Path
754+ * Save Data to Path as a Json Object
755755 *
756- * @param mixed $destination
756+ * @param string $destination
757757 * @param mixed $data
758- * @param bool $type
758+ * @param bool $type - default is JSON_PRETTY_PRINT
759+ * - will save as JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE
759760 *
760- * @return void
761+ * @return bool
761762 */
762- static public function saveDataToPath (? string $ destination = null , array $ data = [], bool $ type = true )
763+ static public function saveDataAsJsonObject ( string $ destination, mixed $ data, ? bool $ type = true )
763764 {
764765 $ format = JSON_PRETTY_PRINT ;
765766 if (!$ type ){
766767 $ format = JSON_UNESCAPED_UNICODE ;
767768 }
768769
769- // JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
770+ // check or convert data to an array
771+ if (!is_array (!$ data )){
772+ $ data = Server::toArray ($ data );
773+ }
774+
775+ // try to read destination
770776 $ fopen = fopen ($ destination , "w " );
771- @fwrite ($ fopen , json_encode ($ data , $ format ));
772- @fclose (@$ fopen );
777+
778+ // must be a type of resource
779+ if (is_resource ($ fopen )){
780+ fwrite ($ fopen , json_encode ($ data , $ format ));
781+ fclose ($ fopen );
782+ return true ;
783+ }
784+
785+ return false ;
773786 }
774787
775788 /**
776789 * Save File From Url
777790 *
778- * @param mixed $urlFile
779- * @param mixed $destination
791+ * @param string|null $url
792+ * @param string|null $destination
780793 * @return string
781794 */
782- static public function saveFileFromURL (? string $ urlFile = null , ? string $ destination = null )
795+ static public function saveFileFromURL ($ url = null , $ destination = null )
783796 {
784- if (!empty ($ urlFile )){
785- @file_put_contents ($ destination , fopen ($ urlFile , 'r ' ));
797+ if (!empty ($ url )){
798+ @file_put_contents ($ destination , fopen ($ url , 'r ' ));
786799 }
787800
788801 return $ destination ;
@@ -791,12 +804,12 @@ static public function saveFileFromURL(?string $urlFile = null, ?string $destina
791804 /**
792805 * Read PDF TO Browser
793806 *
794- * @param mixed $path
807+ * @param string|null $path
795808 * [localhost] PDF path
796809 *
797810 * @return void
798811 */
799- static public function readPDFToBrowser (? string $ path = null )
812+ static public function readPDFToBrowser ($ path = null )
800813 {
801814 if (!empty ($ path ) && self ::exists ($ path )){
802815 // Header content type
@@ -812,10 +825,10 @@ static public function readPDFToBrowser(?string $path = null)
812825 /**
813826 * Convert image to base64
814827 *
815- * @param mixed $path_to_image
828+ * @param string|null $path_to_image
816829 * @return null|string
817830 */
818- static public function imageToBase64 (? string $ path = null )
831+ static public function imageToBase64 ($ path = null )
819832 {
820833 if (!empty ($ path ) && self ::exists ($ path )){
821834 $ type = pathinfo ($ path , PATHINFO_EXTENSION );
@@ -843,7 +856,7 @@ static public function imageToBase64(?string $path = null)
843856 * @return string
844857 * - The masked string.
845858 */
846- static public function mask (? string $ str = null , ?int $ length = 4 , ?string $ position = 'right ' , ?string $ mask = '* ' )
859+ static public function mask ($ str = null , ?int $ length = 4 , ?string $ position = 'right ' , ?string $ mask = '* ' )
847860 {
848861 // Get the length of the string
849862 $ strLength = strlen ($ str );
@@ -888,7 +901,7 @@ static public function mask(?string $str = null, ?int $length = 4, ?string $posi
888901 /**
889902 * Validate an email address.
890903 *
891- * @param string $email
904+ * @param string|null $email
892905 * - The email address to validate.
893906 *
894907 * @param bool $use_internet
@@ -901,7 +914,7 @@ static public function mask(?string $str = null, ?int $length = 4, ?string $posi
901914 * @return bool
902915 * - Whether the email address is valid (true) or not (false).
903916 */
904- static public function emailValidator (? string $ email = null , ?bool $ use_internet = true , ?bool $ server_verify = false )
917+ static public function emailValidator ($ email = null , ?bool $ use_internet = true , ?bool $ server_verify = false )
905918 {
906919 $ filteredEmail = filter_var ($ email , FILTER_VALIDATE_EMAIL );
907920
@@ -968,21 +981,16 @@ static public function decryptStr(string $encryption, string $key, string $passk
968981 // Use openssl_decrypt() function to decrypt the data
969982 return openssl_decrypt ($ encryption , $ ciphering , $ key , $ options , $ passphrase );
970983 }
971-
972- /**
973- * Encrypt string
974- *
975- * @return string
976- */
984+
977985 /**
978986 * Encrypt string
979987 *
980- * @param string $string
988+ * @param string|null $string
981989 * @return string
982990 * - Uses the Open SSL Encryption
983991 * - BF-CBC
984992 */
985- static public function encryptStr (? string $ string = null )
993+ static public function encryptStr ($ string = null )
986994 {
987995 // get encryption
988996 $ openSSL = self ::openSSLEncrypt ();
@@ -1018,15 +1026,15 @@ static public function encryptStr(?string $string = null)
10181026 /**
10191027 * Get platform svg icon set
10201028 *
1021- * @param string $platform
1029+ * @param string|null $platform
10221030 * - windows|linux|android|mobile|phone|unknown|mac|macintosh|ios|iphone|c|os x
10231031 *
1024- * @param string $os_name
1032+ * @param string|null $os_name
10251033 * - macos|os x|ios
10261034 *
10271035 * @return string
10281036 */
1029- static public function platformIcon (? string $ platform = null , ? string $ os_name = null )
1037+ static public function platformIcon ($ platform = null , $ os_name = null )
10301038 {
10311039 // platform to lower
10321040 $ platform = Str::lower (basename ($ platform ));
@@ -1064,14 +1072,14 @@ static public function platformIcon(?string $platform = null, ?string $os_name =
10641072 * - Storage location
10651073 * - public_path/svg_path/
10661074 *
1067- * @param string $payment
1075+ * @param string|null $payment
10681076 * -- add-money|alipay|bank|cc|credit-card|discover|faster-pay|groupbuy|maestro|mastercard
10691077 * -- pay|payme|payment-card|payment-wallet|paypal|stripe-circle|tripe-sqaure|stripe|visa
10701078 *
10711079 * @return mixed
10721080 * - string|null
10731081 */
1074- static public function paymentIcon (? string $ payment = null )
1082+ static public function paymentIcon ($ payment = null )
10751083 {
10761084 // set path
10771085 $ path = self ::stringReplacer ( __DIR__ );
@@ -1105,11 +1113,11 @@ static public function paymentIcon(?string $payment = null)
11051113 /**
11061114 * File exist and not a directory
11071115 *
1108- * @param string $path
1116+ * @param string|null $path
11091117 * @return bool
11101118 * - True|False
11111119 */
1112- static public function exists (? string $ path = null )
1120+ static public function exists ($ path = null )
11131121 {
11141122 return !is_dir ($ path ) && file_exists ($ path );
11151123 }
@@ -1118,10 +1126,10 @@ static public function exists(?string $path = null)
11181126 * Replace and recreate path to
11191127 * - (/) slash
11201128 *
1121- * @param string $path
1129+ * @param string|null $path
11221130 * @return string
11231131 */
1124- static public function stringReplacer (? string $ path = null )
1132+ static public function stringReplacer ($ path = null )
11251133 {
11261134 return Server::cleanServerPath ($ path );
11271135 }
0 commit comments