Skip to content

Commit

Permalink
Changelog 1.22.0 :
Browse files Browse the repository at this point in the history
- Improvement speed performance in app bootstrap
- Update Packager module
- Add Scanner and StringUtils class
  • Loading branch information
aalfiann committed Nov 29, 2018
1 parent 7a79293 commit c104bb7
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 29 deletions.
12 changes: 6 additions & 6 deletions src/app/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

// Autoload all external classes
spl_autoload_register(function ($classname) {
require (realpath(__DIR__ . '/..'). '/'.str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php');
require (realpath(__DIR__ . '/..').DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php');
});

// Set time zone
Expand All @@ -38,10 +38,10 @@
// Set up router cache if enabled in config
if ($config['router']['enableCache'] == true) {
if (!is_dir($config['router']['folderCache'])) mkdir($config['router']['folderCache'],0775,true);
$config['routerCacheFile'] = $config['router']['folderCache'].'/'.$config['router']['fileCache'];
$config['routerCacheFile'] = $config['router']['folderCache'].DIRECTORY_SEPARATOR.$config['router']['fileCache'];
} else {
if (file_exists($config['router']['folderCache'].'/'.$config['router']['fileCache'])) {
unlink($config['router']['folderCache'].'/'.$config['router']['fileCache']);
if (file_exists($config['router']['folderCache'].DIRECTORY_SEPARATOR.$config['router']['fileCache'])) {
unlink($config['router']['folderCache'].DIRECTORY_SEPARATOR.$config['router']['fileCache']);
}
}

Expand All @@ -52,13 +52,13 @@
require __DIR__.'/middleware.php';

// Load all router files before run
$routers = \classes\Scanner::fileSearch('../routers/','router.php');
$routers = \classes\helper\Scanner::fileSearch('../routers/','router.php');
foreach ($routers as $router) {
require $router;
}

// Load all modules router files before run
$modrouters = \classes\Scanner::fileSearch('../modules/','router.php');
$modrouters = \classes\helper\Scanner::fileSearch('../modules/','router.php');
foreach ($modrouters as $modrouter) {
require $modrouter;
}
Expand Down
22 changes: 5 additions & 17 deletions src/classes/Scanner.php → src/classes/helper/Scanner.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
<?php
namespace classes;
namespace classes\helper;
use \classes\helper\StringUtils;

class Scanner {

/**
* Last char checker (alternative to preg_match)
*
* @param match = is the text to match
* @param string = is the source text
*
* @return bool
*/
public static function isMatchLast($match,$string){
if (substr($string, (-1 * abs(strlen($match)))) == $match) return true;
return false;
}

/**
* fileSearch is using opendir (very fast)
*
Expand All @@ -41,7 +29,7 @@ public static function fileSearch($dir, $ext='php',$extIsRegex=false) {
if($extIsRegex){
if(preg_match($ext, $file)) array_push($files, $filepath);
} else {
if(self::isMatchLast($ext,$file)) array_push($files, $filepath);
if(StringUtils::isMatchLast($ext,$file)) array_push($files, $filepath);
}
}
}
Expand Down Expand Up @@ -104,7 +92,7 @@ public static function recursiveCallbackIterator($dir,$ext='php',$extIsRegex=fal
if($extIsRegex){
if($current->isFile() && preg_match($pattern, $current->getFilename())) return true;
} else {
if($current->isFile() && self::isMatchLast($ext, $current->getFilename())) return true;
if($current->isFile() && StringUtils::isMatchLast($ext, $current->getFilename())) return true;
}
});
return new \RecursiveIteratorIterator($filter);
Expand All @@ -121,7 +109,7 @@ public static function recursiveCallbackIterator($dir,$ext='php',$extIsRegex=fal
public static function recursiveGlob($pattern, $flags = 0){
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir){
$files = array_merge($files, self::recursiveGlob($dir.'/'.basename($pattern), $flags));
$files = array_merge($files, self::recursiveGlob($dir.DIRECTORY_SEPARATOR.basename($pattern), $flags));
}
return $files;
}
Expand Down
43 changes: 43 additions & 0 deletions src/classes/helper/StringUtils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace classes\helper;

class StringUtils {
/**
* First char checker (alternative to preg_match)
*
* @param match = is the text to match
* @param string = is the source text
*
* @return bool
*/
public static function isMatchFirst($match,$string){
if (substr($string, 0, abs(strlen($match))) == $match) return true;
return false;
}

/**
* Any char checker (alternative to preg_match)
*
* @param match = is the text to match
* @param string = is the source text
*
* @return bool
*/
public static function isMatchAny($match,$string){
if(strpos($string,$match) !== false) return true;
return false;
}

/**
* Last char checker (alternative to preg_match)
*
* @param match = is the text to match
* @param string = is the source text
*
* @return bool
*/
public static function isMatchLast($match,$string){
if (substr($string, (-1 * abs(strlen($match)))) == $match) return true;
return false;
}
}
31 changes: 26 additions & 5 deletions src/modules/packager/Packager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,32 @@ private function dirname_r($path, $count=1){
return dirname($path);
}

private function glob_recursive($pattern, $flags = 0){
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir){
$files = array_merge($files, $this->glob_recursive($dir.'/'.basename($pattern), $flags));
private function isMatchLast($match,$string){
if (substr($string, (-1 * abs(strlen($match)))) == $match) return true;
return false;
}

private function fileSearch($dir, $ext='php',$extIsRegex=false) {
$files = [];
$fh = opendir($dir);

while (($file = readdir($fh)) !== false) {
if($file == '.' || $file == '..')
continue;

$filepath = $dir . DIRECTORY_SEPARATOR . $file;

if (is_dir($filepath))
$files = array_merge($files, $this->fileSearch($filepath, $ext));
else {
if($extIsRegex){
if(preg_match($ext, $file)) array_push($files, $filepath);
} else {
if($this->isMatchLast($ext,$file)) array_push($files, $filepath);
}
}
}
closedir($fh);
return $files;
}

Expand Down Expand Up @@ -149,7 +170,7 @@ public function showAll(){
$role = Auth::getRoleID($this->db,$this->token);
if ($role == 1) {
// Scan all packages
$packs = $this->glob_recursive('../modules/*/package.json',GLOB_NOSORT);
$packs = $this->fileSearch('../modules/','package.json');
$listmodules = str_replace(['../modules/','/package.json'],'',$packs);
foreach ($packs as $pack) {
$mods = json_decode(file_get_contents($pack));
Expand Down
2 changes: 1 addition & 1 deletion src/modules/packager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Packager",
"url": "https://github.com/aalfiann/reSlim-modules-packager",
"description": "A modules to make easy for manage the packages for reSlim",
"version": "1.5",
"version": "1.6",
"require": {
"reSlim": "1.10.0"
},
Expand Down

0 comments on commit c104bb7

Please sign in to comment.