yet another github api refactoring
[pharext/pharext.org] / app / Github / API / Repos / ContentsCallback.php
diff --git a/app/Github/API/Repos/ContentsCallback.php b/app/Github/API/Repos/ContentsCallback.php
new file mode 100644 (file)
index 0000000..c08c3c2
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace app\Github\API\Repos;
+
+use app\Github\API;
+use app\Github\API\Callback;
+
+class ContentsCallback extends Callback
+{
+       private $repo;
+       
+       function __construct(API $api, $repo) {
+               parent::__construct($api);
+               $this->repo = $repo;
+       }
+       
+       function __invoke($json, $links = null) {
+               foreach ($json as $entry) {
+                       if ($entry->type !== "file" || $entry->size <= 0) {
+                               continue;
+                       }
+                       if ($entry->name === "config.m4" || fnmatch("config?.m4", $entry->name)) {
+                               $this->repo->config_m4 = $entry->name;
+                       } elseif ($entry->name === "package.xml" || $entry->name === "package2.xml") {
+                               $this->repo->package_xml = $entry->name;
+                       } elseif ($entry->name === "pharext_package.php") {
+                               $this->repo->pharext_package_php = $entry->name;
+                       }
+               }
+       }
+}