Skip to content

Commit

Permalink
Add type hint
Browse files Browse the repository at this point in the history
  • Loading branch information
carry0987 committed Nov 13, 2023
1 parent 412ab01 commit c6f26b2
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 73 deletions.
36 changes: 18 additions & 18 deletions src/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function setOptions(array $options)
$this->options = $options;
}

public function loadTemplate($file)
public function loadTemplate(string $file)
{
if ($this->template === null) {
self::throwError('Template class not found');
Expand All @@ -50,22 +50,22 @@ public function loadTemplate($file)
/* Static file cache */
/* CSS */
//Get CSS file path
private function trimCSSName($file)
private function trimCSSName(string $file)
{
return str_replace('.css', '', $file);
}

private function placeCSSName($place)
private function placeCSSName(string | array $place)
{
return (is_array($place)) ? substr(md5(implode('-', $place)), 0, 6) : $place;
}

private function getCSSFile($file)
private function getCSSFile(string $file)
{
return Utils::trimPath($this->options['css_dir'].Template::DIR_SEP.$file);
}

private function getCSSCache($file, $place)
private function getCSSCache(string $file, string | array $place)
{
$file = Utils::trimRelativePath($file);
$place = $this->placeCSSName($place);
Expand All @@ -74,15 +74,15 @@ private function getCSSCache($file, $place)
}

//Get CSS version file path
private function getCSSVersionFile($file)
private function getCSSVersionFile(string $file)
{
$file = Utils::trimRelativePath($file);
$file = preg_replace('/\.[a-z0-9\-_]+$/i', '.cssversion.json', $file);
return Utils::trimPath($this->options['cache_dir'].Template::DIR_SEP.$file);
}

//Store CSS version value
private function cssSaveVersion($file, $css_md5 = null)
private function cssSaveVersion(string $file, string $css_md5 = null)
{
//Get CSS file
$css_file = $this->getCSSFile($file);
Expand Down Expand Up @@ -138,7 +138,7 @@ private function cssSaveVersion($file, $css_md5 = null)
}

//Check CSS file's change
private function cssVersionCheck($file, $css_md5 = null)
private function cssVersionCheck(string $file, string $css_md5 = null)
{
$result = array();
$result['update'] = false;
Expand Down Expand Up @@ -202,7 +202,7 @@ public function loadCSSFile(string $file)
}

//Parse CSS File
private function parseCSSFile(string $file, $place)
private function parseCSSFile(string $file, string | array $place)
{
$css_tplfile = $this->getCSSFile($file);
if (!is_readable($css_tplfile)) {
Expand All @@ -223,7 +223,7 @@ private function parseCSSFile(string $file, $place)
}

//Parse CSS Template
private function parseCSSTemplate($file, $place, $get_md5 = false)
private function parseCSSTemplate(string $file, string | array $place, bool $get_md5 = false)
{
$css_tplfile = $this->getCSSFile($file);
if (!is_readable($css_tplfile)) {
Expand Down Expand Up @@ -258,7 +258,7 @@ private function parseCSSTemplate($file, $place, $get_md5 = false)
return $cachefile;
}

private function parse_csstpl($result, $matches, $param)
private function parse_csstpl(int $result, array $matches, string $param)
{
$content = false;
if ($result === 1) {
Expand All @@ -272,7 +272,7 @@ private function parse_csstpl($result, $matches, $param)
}

//Load CSS Template
public function loadCSSTemplate($file, $place)
public function loadCSSTemplate(string $file, string | array $place)
{
if (is_array($place)) {
$place = (count($place) > 1) ? $place : $place[0];
Expand Down Expand Up @@ -306,26 +306,26 @@ public function loadCSSTemplate($file, $place)

/* JS */
//Get JS file path
private function trimJSName($file)
private function trimJSName(string $file)
{
return str_replace('.js', '', $file);
}

private function getJSFile($file)
private function getJSFile(string $file)
{
return Utils::trimPath($this->options['js_dir'].Template::DIR_SEP.$file);
}

//Get JS version file path
private function getJSVersionFile($file)
private function getJSVersionFile(string $file)
{
$file = Utils::trimRelativePath($file);
$file = preg_replace('/\.[a-z0-9\-_]+$/i', '.jsversion.txt', $file);
return Utils::trimPath($this->options['cache_dir'].Template::DIR_SEP.$file);
}

//Store JS version value
private function jsSaveVersion($file)
private function jsSaveVersion(string $file)
{
//Get JS file
$js_file = $this->getJSFile($file);
Expand Down Expand Up @@ -359,7 +359,7 @@ private function jsSaveVersion($file)
}

//Check JS file's change
private function jsVersionCheck($file)
private function jsVersionCheck(string $file)
{
$result = array();
$result['update'] = false;
Expand Down Expand Up @@ -388,7 +388,7 @@ private function jsVersionCheck($file)
}

//Load JS files
public function loadJSFile($file)
public function loadJSFile(string $file)
{
if ($this->connectdb !== null || $this->redis !== null) {
$js_file = $this->trimJSName($file);
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/DBController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getVersion(string $tpl_path, string $tpl_name, string $tpl_type)
}
}

public function createVersion($tpl_path, $tpl_name, $tpl_type, $tpl_md5, $tpl_expire_time, $tpl_verhash)
public function createVersion(string $tpl_path, string $tpl_name, string $tpl_type, string $tpl_md5, int $tpl_expire_time, string $tpl_verhash)
{
$tpl_query = 'INSERT INTO '.self::$table.' (tpl_path, tpl_name, tpl_type, tpl_md5, tpl_expire_time, tpl_verhash)
VALUES (:path, :name, :type, :md5, :expire_time, :verhash)';
Expand All @@ -72,7 +72,7 @@ public function createVersion($tpl_path, $tpl_name, $tpl_type, $tpl_md5, $tpl_ex
}
}

public function updateVersion($tpl_path, $tpl_name, $tpl_type, $tpl_md5, $tpl_expire_time, $tpl_verhash)
public function updateVersion(string $tpl_path, string $tpl_name, string $tpl_type, string $tpl_md5, int $tpl_expire_time, string $tpl_verhash)
{
$tpl_query = 'UPDATE '.self::$table.'
SET tpl_md5 = :md5, tpl_expire_time = :expire_time, tpl_verhash = :verhash
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/RedisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function setHashName(string $hash)
return $this;
}

public function getVersion($get_tpl_path, $get_tpl_name, $get_tpl_type)
public function getVersion(string $get_tpl_path, string $get_tpl_name, string $get_tpl_type)
{
if ($this->redis === null) return false;
$tpl_key = "template::$get_tpl_path::$get_tpl_name::$get_tpl_type";
Expand All @@ -44,7 +44,7 @@ public function getVersion($get_tpl_path, $get_tpl_name, $get_tpl_type)
return false;
}

public function createVersion($tpl_path, $tpl_name, $tpl_type, $tpl_md5, $tpl_expire_time, $tpl_verhash)
public function createVersion(string $tpl_path, string $tpl_name, string $tpl_type, string $tpl_md5, int $tpl_expire_time, string $tpl_verhash)
{
if ($this->redis === null) return false;
$tpl_key = "template::$tpl_path::$tpl_name::$tpl_type";
Expand All @@ -57,7 +57,7 @@ public function createVersion($tpl_path, $tpl_name, $tpl_type, $tpl_md5, $tpl_ex
return $this->redis->setHashValue($this->hash, $tpl_key, serialize($tpl_data));
}

public function updateVersion($tpl_path, $tpl_name, $tpl_type, $tpl_md5, $tpl_expire_time, $tpl_verhash)
public function updateVersion(string $tpl_path, string $tpl_name, string $tpl_type, string $tpl_md5, int $tpl_expire_time, string $tpl_verhash)
{
return $this->createVersion($tpl_path, $tpl_name, $tpl_type, $tpl_md5, $tpl_expire_time, $tpl_verhash);
}
Expand Down
Loading

0 comments on commit c6f26b2

Please sign in to comment.