-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move cache handling code to own file.
- Loading branch information
Showing
4 changed files
with
120 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php namespace Netcarver; | ||
|
||
class FileCache { | ||
/** | ||
* | ||
*/ | ||
protected $cache_dir = null; | ||
|
||
|
||
/** | ||
* | ||
*/ | ||
public function setCacheDirectory($dir = null) { | ||
if (is_string($dir) && !empty($dir)) { | ||
$this->cache_dir = realpath("$dir/"); | ||
} else { | ||
$this->cache_dir = dirname(__FILE__) . "/cache"; | ||
} | ||
} | ||
|
||
|
||
|
||
/** | ||
* | ||
*/ | ||
protected function urlToKey($url) { | ||
$key = str_replace('https://', '', strtolower($url)); | ||
$key = str_replace(['/',':','?','#', '%'], '-', $key); | ||
return $key; | ||
} | ||
|
||
|
||
|
||
|
||
/** | ||
* | ||
*/ | ||
protected function keyToStorageLocation($key) { | ||
$dir = $this->cache_dir; | ||
if (!$dir || !is_readable($dir)) { | ||
throw new \Exception("Cache directory is invalid or unreadable."); | ||
} | ||
$location = "{$this->cache_dir}/$key"; | ||
return $location; | ||
} | ||
|
||
|
||
|
||
/** | ||
* | ||
*/ | ||
protected function getEntryForKey($key) { | ||
$file = $this->keyToStorageLocation($key); | ||
$entry = @file_get_contents($file); | ||
if ($entry) { | ||
if (is_callable('gzinflate')) { | ||
$entry = gzinflate($entry); | ||
} | ||
$entry = json_decode($entry, true); | ||
return $entry; | ||
} | ||
return null; | ||
} | ||
|
||
|
||
|
||
/** | ||
* | ||
*/ | ||
protected function setEntryForKey($key, $entry) { | ||
$file = $this->keyToStorageLocation($key); | ||
$entry = json_encode($entry); | ||
if (is_callable('gzdeflate')) { | ||
$entry = gzdeflate($entry); | ||
} | ||
file_put_contents($file, $entry); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
<?php namespace Netcarver; | ||
|
||
interface GitRepositoryInterface { | ||
public function __construct($http, $remote, $application, array $options); | ||
public function GetInfo(); | ||
public function GetTags(); | ||
public function GetCommits($startref, $endref='HEAD'); | ||
public function GetChangelog(); | ||
public function GetForks($sort); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters