You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.0 KiB

  1. <?php
  2. class RepositoryDir {
  3. function __construct ($id, $def) {
  4. $this->def = $def;
  5. $this->path = $def['path'];
  6. }
  7. function info () {
  8. $ret = array();
  9. foreach (array('name') as $k) {
  10. if (array_key_exists($k, $this->def)) {
  11. $ret[$k] = $this->def[$k];
  12. }
  13. }
  14. $ret['timestamp'] = Date(DATE_ISO8601, $this->timestamp());
  15. return $ret;
  16. }
  17. function timestamp () {
  18. $ts = 0;
  19. $d = opendir($this->path);
  20. while ($f = readdir($d)) {
  21. $t = filemtime("{$this->path}/{$f}");
  22. if ($t > $ts) {
  23. $ts = $t;
  24. }
  25. }
  26. closedir($d);
  27. return $ts;
  28. }
  29. function data () {
  30. $data = array();
  31. $d = opendir($this->path);
  32. while ($f = readdir($d)) {
  33. if (preg_match("/^([0-9a-zA-Z_\-]+)\.json$/", $f, $m) && $f !== 'package.json') {
  34. $d1 = json_decode(file_get_contents("{$this->path}/{$f}"), true);
  35. $data[$m[1]] = jsonMultilineStringsJoin($d1, array('exclude' => array(array('const'))));
  36. }
  37. }
  38. closedir($d);
  39. return $data;
  40. }
  41. }