Browse Source

Repository: split common code to RepositoryBase

master
Stephan Bösch-Plepelits 7 years ago
parent
commit
4997dd55de
  1. 1
      modulekit.php
  2. 32
      src/RepositoryBase.php
  3. 26
      src/RepositoryDir.php
  4. 26
      src/RepositoryGit.php

1
modulekit.php

@ -16,6 +16,7 @@ $include = array(
'src/ip-location.php',
'src/wikipedia.php',
'src/ImageLoader.php',
'src/RepositoryBase.php',
'src/RepositoryDir.php',
'src/RepositoryGit.php',
'src/repositories.php',

32
src/RepositoryBase.php

@ -0,0 +1,32 @@
<?php
class RepositoryBase {
function __construct ($id, $def) {
$this->def = $def;
$this->path = $def['path'];
}
function timestamp () {
return null;
}
function info () {
$ret = array();
foreach (array('name') as $k) {
if (array_key_exists($k, $this->def)) {
$ret[$k] = $this->def[$k];
}
}
$ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp());
return $ret;
}
function data () {
$data = array(
'categories' => array(),
'timestamp' => Date(DATE_ISO8601, $this->timestamp()),
);
}
}

26
src/RepositoryDir.php

@ -1,24 +1,5 @@
<?php
class RepositoryDir {
function __construct ($id, $def) {
$this->def = $def;
$this->path = $def['path'];
}
function info () {
$ret = array();
foreach (array('name') as $k) {
if (array_key_exists($k, $this->def)) {
$ret[$k] = $this->def[$k];
}
}
$ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp());
return $ret;
}
class RepositoryDir extends RepositoryBase {
function timestamp () {
$ts = 0;
$d = opendir($this->path);
@ -34,10 +15,7 @@ class RepositoryDir {
}
function data () {
$data = array(
'categories' => array(),
'timestamp' => Date(DATE_ISO8601, $this->timestamp()),
);
$data = parent::data();
$d = opendir($this->path);
while ($f = readdir($d)) {

26
src/RepositoryGit.php

@ -1,24 +1,5 @@
<?php
class RepositoryGit {
function __construct ($id, $def) {
$this->def = $def;
$this->path = $def['path'];
}
function info () {
$ret = array();
foreach (array('name') as $k) {
if (array_key_exists($k, $this->def)) {
$ret[$k] = $this->def[$k];
}
}
$ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp());
return $ret;
}
class RepositoryGit extends RepositoryBase {
function timestamp () {
$ts = (int)shell_exec("cd " . escapeShellArg($this->path) . "; git log -1 --pretty=format:%ct");
@ -26,10 +7,7 @@ class RepositoryGit {
}
function data () {
$data = array(
'categories' => array(),
'timestamp' => Date(DATE_ISO8601, $this->timestamp()),
);
$data = parent::data();
$d = popen("cd " . escapeShellArg($this->path) . "; git ls-tree HEAD", "r");
while ($r = fgets($d)) {

Loading…
Cancel
Save