Skip to content

Commit

Permalink
Fixed init data and cache dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
isofarro committed Jun 17, 2009
1 parent 82459ac commit c4f7a54
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
15 changes: 11 additions & 4 deletions CanonicalLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
of link shorteners, and iframe/frames based toolbar (e.g. Digg)
**/
class CanonicalLink {
var $config;
var $config = array(
'dataDir' => 'canonical-link',
'dataFile' => 'links.ser'
);
var $cache;
var $http;

Expand All @@ -15,11 +18,14 @@ public function __construct($config=false) {
if ($config) {
$this->setConfig($config);
}
$this->_init();
}

public function setConfig($config) {
$this->config = $config;
$this->_init();
if (is_array($config)) {
$this->config = array_merge( $this->config, $config );
}
//$this->config = $config;
}

public function getCanonicalLink($url) {
Expand Down Expand Up @@ -68,7 +74,8 @@ protected function _getUrl($url) {
}

protected function _init() {

$path = HttpUtilsConstants::initDataDir($this->config['dataDir']);
echo "Path: {$path}\n";
}
}

Expand Down
27 changes: 24 additions & 3 deletions HttpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,36 @@ public function getBaseDataDir() {
}

public function initCacheDir($segment) {
$baseDir = self::getBaseDataDir();
return mkdir($cacheDir . $segment);
$baseDir = self::getBaseCacheDir();
$path = $baseDir . $segment;
return self::initDir($path);
}

public function initDataDir($segment) {
$baseDir = self::getBaseDataDir();
return mkdir($baseDir . $segment);
$path = $baseDir . $segment;
return self::initDir($path);
}

public function initDir($path) {
$exists = file_exists($path);
$isDir = false;

if (!$exists) {
$exists = mkdir($path);
}

if (!$exists) {
//exit("Can't create directory {$path}\n");
return NULL;
}

if ($exists && is_dir($path)) {
return $path . '/';
}
//exit("File already exists {$path}, and isn't a directory.\n");
return NULL;
}
}

?>
7 changes: 7 additions & 0 deletions tests/CanonicalLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public function setUp() {
$this->canon = new CanonicalLink();
}

public function testInit() {


}

/****
public function testNormalUrl() {
$url = 'http://www.isolani.co.uk/';
$canonUrl = $this->canon->getCanonicalLink($url);
Expand All @@ -26,6 +32,7 @@ public function testTinyUrl() {
$canonUrl = $this->canon->getCanonicalLink($url);
$this->assertEquals($endUrl, $canonUrl);
}
****/

}

Expand Down

0 comments on commit c4f7a54

Please sign in to comment.